我最近开始使用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(我正在使用Mock对象)。
将此行添加到mox.py中ExpectedMethodCallsError的 str 方法的顶部可以解决问题(或者无论如何都是这个症状):
if isinstance(self._expected_methods, str):
self._expected_methods = self._expected_methods.split("\n")
答案 0 :(得分:3)
正如Aaron Digulla指出的那样,问题不在于鼻子,而在于Mox(我正在使用Mock对象)。
将此行添加到mox.py中ExpectedMethodCallsError的 str 方法的顶部可以解决问题(或者无论如何都是这个症状):
if isinstance(self._expected_methods, basestring):
self._expected_methods = self._expected_methods.split("\n")
答案 1 :(得分:2)
ExpectedMethodCallsError
的{{1}}或__repr__
方法似乎有误。
或者在__str__
。
答案 2 :(得分:2)
我不能直接解决你的问题,但我知道如何生成类似的。看起来鼻子遍历堆栈跟踪:
for line in lines:
print "%s" % line
如果出于某种原因,变量lines
是一个字符串,则会迭代字符串而不是行(导致每个字符打印一行,就像你的情况一样)。
问题是什么:我不知道:)
答案 3 :(得分:1)
在我的系统上,我发现该字符串是作为unicode传入的,另外一个测试用例将涵盖这个:
if (isinstance(self._expected_methods, str) or
isinstance(self._expected_methods, unicode)):
self._expected_methods = self._expected_methods.split("\n")