Python 鼻子测试(实际上错误来自 Mox)每行打印一个字符的错误(带有行号!)
我最近开始使用 Nose 进行单元测试。它非常好,只是有时发生错误时它会以一种非常奇怪的方式打印出错误信息。它将其分成每行 1 个字符,然后将其与行号一起打印出来。有谁知道如何解决这个问题?
....F...............
======================================================================
FAIL: accounts.tests.testaccountserver.test_create_account_writes_an_account_to_the_store
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tom/envs/myappshare/lib/python2.7/site-packages/nose/case.py", line 187, in runTest
self.test(*self.arg)
File "/media/Shared/Dropbox/jobs/myapp/myappshare/src/accounts/tests/testaccountserver.py", line 102, in test_create_account_writes_an_account_to_the_store
mox.VerifyAll()
File "/home/tom/envs/myappshare/lib/python2.7/site-packages/mox.py", line 286, in VerifyAll
mock_obj._Verify()
File "/home/tom/envs/myappshare/lib/python2.7/site-packages/mox.py", line 506, in _Verify
raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
0. V
1. e
2. r
3. i
4. f
5. y
6. :
7.
8. E
9. x
10. p
11. e
12. c
13. t
14. e
15. d
16.
17. m
18. e
以此类推 1346 行!
编辑:
它不会让我在 8 小时内回答我自己的问题,所以我正在编辑我找到的解决方案:
正如 Aaron Digulla 指出的那样,问题不在鼻子中,而是在 Mox 中(我用它来模拟对象) )。
将此行添加到 mox.py 中 ExpectedMethodCallsError 的 str 方法的顶部修复了问题(或者无论如何都是这种症状):
if isinstance(self._expected_methods, str):
self._expected_methods = self._expected_methods.split("\n")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Aaron Digulla 指出的那样,问题不在于鼻子,而在于 Mox(我用它来模拟对象)。
将此行添加到 mox.py 中 ExpectedMethodCallsError 的 str 方法的顶部修复了问题(或者无论如何都是这种症状):
As Aaron Digulla points out the problem is not in nose but in Mox (which I'm using to Mock objects).
Adding this line to the top of str method of ExpectedMethodCallsError in mox.py fixes the problem (or this symptom anyway):
ExpectedMethodCallsError
的__repr__
或__str__
方法中似乎存在错误。或者在
mock_obj
中注册预期方法的代码中。There seems to be an error in
ExpectedMethodCallsError
's__repr__
or__str__
method.Or in the code which registers the expected methods in
mock_obj
.我无法直接解决你的问题,但我知道如何生成类似的问题。似乎鼻子会迭代堆栈跟踪:
如果由于某种原因,变量
lines
是一个字符串,则将迭代该字符串而不是行(导致每个字符打印一行,就像您的情况一样) 。至于问题是什么:我不知道:)
I can't directly solve your problem, but I know how to generate similar. It seems that nose iterates through the stack trace:
If for some reason, variable
lines
is a string, the string will be iterated instead of lines (resulting in one line per character printing just like in your case).As of what is the problem: I don't know :)
在我的系统上,我发现字符串被作为 unicode 传入,一个额外的测试用例将涵盖这一点:
On my system I found the string was being passed in as unicode, an additional test case will cover this: