Python nose tests (actually the error is from Mox) print out errors one character per line (with line numbers!)
I've recently started using Nose for my unit tests. It's pretty good except that sometimes when an error occurs it prints out the error information in a really weird way. It splits it up into 1 character per line then prints it out with line numbers. Does anyone have any idea how to fix this?
....F...............
======================================================================
FAIL: accounts.tests.testaccountserver.test_create_accoun开发者_运维知识库t_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
And so on for 1346 lines!
EDIT:
It won't let me answer my own question for 8 hours, so I'm editing in the solution I found:
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):
if isinstance(self._expected_methods, str):
self._expected_methods = self._expected_methods.split("\n")
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):
if isinstance(self._expected_methods, basestring):
self._expected_methods = self._expected_methods.split("\n")
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
.
I can't directly solve your problem, but I know how to generate similar. It seems that nose iterates through the stack trace:
for line in lines:
print "%s" % line
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 :)
On my system I found the string was being passed in as unicode, an additional test case will cover this:
if (isinstance(self._expected_methods, str) or
isinstance(self._expected_methods, unicode)):
self._expected_methods = self._expected_methods.split("\n")
精彩评论