[Twisted-Python] asserting an exception wrapped in a defer.FirstError

Jorge Gonzalez gjorge at google.com
Mon Aug 5 17:20:30 MDT 2013


In a trial test case like this:

-----------------------------------------------------------------------------------------------------------------------
*def testFailureFromDeferredList(self):*
*    d = defer.fail(ValueError('bad value'))*
*    return self.assertFailure(defer.gatherResults([d]), ValueError)*
-----------------------------------------------------------------------------------------------------------------------

I get the following FAIL and ERROR:

-----------------------------------------------------------------------------------------------------------------------
*[FAIL]
*
*Traceback (most recent call last):*
*  File "/home/gjorge/tmp/
buildbot.net/python_sandbox/local/lib/python2.7/site-packages/twisted/trial/_asynctest.py",
line 74, in _eb*
*    raise self.failureException(output)*
*twisted.trial.unittest.FailTest: *
*Expected: (<type 'exceptions.ValueError'>,)*
*Got:*
*[Failure instance: Traceback (failure with no frames): <class
'twisted.internet.defer.FirstError'>: FirstError[#0, [Failure instance:
Traceback (failure with no frames): <type 'exceptions.ValueError'>: bad
value*
*]]*
*]*
*
*
*
===============================================================================
*
*[ERROR]*
*Traceback (most recent call last):*
*Failure: exceptions.ValueError: bad value*
-----------------------------------------------------------------------------------------------------------------------

If I try to remedy this by asserting I get a defer.FirstError instead of a
ValueError:
-----------------------------------------------------------------------------------------------------------------------
*def testFailureFromDeferredList(self):*
*    d = defer.fail(ValueError('bad value'))*
*    return self.assertFailure(defer.gatherResults([d]), defer.FirstError)*
-----------------------------------------------------------------------------------------------------------------------

 I still get an Error:
-----------------------------------------------------------------------------------------------------------------------
*[ERROR]*
*Traceback (most recent call last):*
*Failure: exceptions.ValueError: bad value*
-----------------------------------------------------------------------------------------------------------------------

Is there another way to assert ValueError was raised?

Thanks,
Jorge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130805/1879016a/attachment.html>


More information about the Twisted-Python mailing list