如何解决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\")
解决方法
正如亚伦·迪古拉(Aaron Digulla)指出的那样,问题不在于鼻子,而在于Mox(我用来模拟对象)。
将此行添加到mox.py的ExpectedMethodCallsError的str方法的顶部可解决此问题(或者仍然是此症状):
if isinstance(self._expected_methods,basestring):
self._expected_methods = self._expected_methods.split(\"\\n\")
,ExpectedMethodCallsError
的__repr__
或__str__
方法似乎有错误。
或在which6ѭ中注册所需方法的代码中。
,我无法直接解决您的问题,但我知道如何生成类似问题。鼻子似乎遍历了堆栈跟踪:
for line in lines:
print \"%s\" % line
如果由于某种原因,变量lines
是一个字符串,则将迭代该字符串而不是行(与您的情况相同,每字符打印一行)。
出了什么问题:我不知道:)
,在我的系统上,我发现该字符串以unicode的形式传入,另外一个测试用例将涵盖此内容:
if (isinstance(self._expected_methods,str) or
isinstance(self._expected_methods,unicode)):
self._expected_methods = self._expected_methods.split(\"\\n\")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。