我最近开始在单元测试中使用鼻子。这是非常好的,但有时当错误发生时,它会以一种非常奇怪的方式输出错误信息。它将它分割成一行一个字符,然后用行号打印出来。有人知道怎么解决这个问题吗?
....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 (我用它来模拟对象)。
将这一行添加到ExpectedMethodCallsError的str方法的mox.py中,可以解决这个问题(或者这个症状):
if isinstance(self._expected_methods, str):
self._expected_methods = self._expected_methods.split("\n")发布于 2011-05-26 08:55:17
正如Aaron Digulla所指出的,问题不在于鼻子,而在于Mox (我用它来模拟对象)。
将这一行添加到ExpectedMethodCallsError的str方法的mox.py中,可以解决这个问题(或者这个症状):
if isinstance(self._expected_methods, basestring):
self._expected_methods = self._expected_methods.split("\n")发布于 2011-05-25 12:06:28
ExpectedMethodCallsError的__repr__或__str__方法似乎有错误。
或者在在mock_obj中注册预期方法的代码中。
发布于 2011-05-25 12:08:01
我不能直接解决你的问题,但我知道如何产生类似的问题。看起来鼻子遍历堆栈跟踪:
for line in lines:
print "%s" % line如果由于某种原因,变量lines是一个字符串,则该字符串将被迭代而不是行(导致每个字符打印一行,就像在您的例子中一样)。
问题是什么?我不知道:)
https://stackoverflow.com/questions/6124180
复制相似问题