New issue 13 by alan.franzoni: ExpectedMethodCallsError problems with async
code (twisted)
http://code.google.com/p/pymox/issues/detail?id=13
Hello,
while i like Mox, I've encountered a small issue when testing async twisted
code running trial (the twisted builtin test tool, supporting different
reactors, output, debugging, etc).
Since twisted wraps exceptions into failures, it may happen that, in order:
- VerifyAll() is called in a test method, but a certain expected method is
not called;
- a deferred is returned by the same method;
- the deferred then triggers a callback that calls the expected method:
this is what the trial output look like:
===============================================================================
[ERROR]: test_mox_async.AsyncMoxTestCase.testAsyncMox
Traceback (most recent call last):
File
"/home/alan/Private/Dropbox/code/mox-0.5.1.fixtraceback/test_mox_async.py",
line 24, in testAsyncMox
m.VerifyAll()
File "/home/alan/Private/Dropbox/code/mox-0.5.1.fixtraceback/mox.py",
line 198, in VerifyAll
mock_obj._Verify()
File "/home/alan/Private/Dropbox/code/mox-0.5.1.fixtraceback/mox.py",
line 353, in _Verify
raise ExpectedMethodCallsError(self._expected_calls_queue)
mox.ExpectedMethodCallsError: Verify: Expected methods never called:
The error is raised but, since the call has happened (too late, e.g. after
VerifyAll(), but it has happened), I can't see what the problem really is.
you can see the problem by yourself by running the attached file on a
system with twisted 8.2 installed:
trial test_mox_async.py
This seems to be caused by the fact that the exception instance saves the
call queue and concatenates the string to be shown just when __str__ is
called (and that's too late when using trial and twisted).
The attached patch saves formatted calls on init, preventing further issues.
output on a patched Mox:
===============================================================================
[ERROR]: test_mox_async.AsyncMoxTestCase.testAsyncMox
Traceback (most recent call last):
File
"/home/alan/Private/Dropbox/code/mox-0.5.1.fixtraceback/test_mox_async.py",
line 24, in testAsyncMox
m.VerifyAll()
File "/home/alan/Private/Dropbox/code/mox-0.5.1.fixtraceback/mox.py",
line 198, in VerifyAll
mock_obj._Verify()
File "/home/alan/Private/Dropbox/code/mox-0.5.1.fixtraceback/mox.py",
line 353, in _Verify
raise ExpectedMethodCallsError(self._expected_calls_queue)
mox.ExpectedMethodCallsError: Verify: Expected methods never called:
0. __call__('value') -> None
-------------------------------------------------------------------------------
Ran 1 tests in 0.007s
FAILED (errors=1)
Attachments:
mox.calltraceback.patch 848 bytes
test_mox_async.py 598 bytes
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings