Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.trial.unittest import TestCase
- from twisted.internet import defer, reactor
- from twisted.internet.defer import DeferredList, Deferred
- def deferredException(x):
- d = defer.Deferred()
- reactor.callLater(0.5, d.errback, x * 3)
- return d
- class Blah(TestCase):
- def test_blah(self):
- dl = DeferredList([
- deferredException(1),
- deferredException(2),
- deferredException(3),
- ])
- def testGotErrors(result_list):
- for success, result in result_list:
- # These will all succeed.
- self.assertFalse(success)
- # In fact at this point, we have no errors, no reason to suspect anything is wrong.
- # But when the DebugInfo objects are GarbageCollected, they log all three errors
- # and the _LogObserver turns those into unittest ERROR outputs.
- # We can try to clear the logs, but because the errors haven't yet been created
- # clearing the logs results in hair-loss, general screaming, and swearing in comments
- # because the test still errors.
- self.flushLoggedErrors()
- return dl.addCallback(testGotErrors)
Add Comment
Please, Sign In to add comment