Guest User

Untitled

a guest
Apr 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. from twisted.trial.unittest import TestCase
  2. from twisted.internet import defer, reactor
  3. from twisted.internet.defer import DeferredList, Deferred
  4.  
  5. def deferredException(x):
  6. d = defer.Deferred()
  7. reactor.callLater(0.5, d.errback, x * 3)
  8. return d
  9.  
  10. class Blah(TestCase):
  11. def test_blah(self):
  12. dl = DeferredList([
  13. deferredException(1),
  14. deferredException(2),
  15. deferredException(3),
  16. ])
  17. def testGotErrors(result_list):
  18. for success, result in result_list:
  19. # These will all succeed.
  20. self.assertFalse(success)
  21.  
  22. # In fact at this point, we have no errors, no reason to suspect anything is wrong.
  23. # But when the DebugInfo objects are GarbageCollected, they log all three errors
  24. # and the _LogObserver turns those into unittest ERROR outputs.
  25.  
  26. # We can try to clear the logs, but because the errors haven't yet been created
  27. # clearing the logs results in hair-loss, general screaming, and swearing in comments
  28. # because the test still errors.
  29. self.flushLoggedErrors()
  30. return dl.addCallback(testGotErrors)
Add Comment
Please, Sign In to add comment