[Twisted-Python] Blocking on deferreds during unit tests (e.g. deferredResult)

Glyph Lefkowitz glyph at divmod.com
Fri May 6 14:24:46 EDT 2005


Eric Mangold wrote:
> I'm starting a new thread on this because It's very important to me, 
> and  we need to have some kind of resolution on this issue.

> Is there a better way to synchronously spin the reactor until a 
> deferred  fires?

Yep.  Write a unit test framework that uses Stackless and create a 
tasklet for each deferred that you want to run.

> There any many cases in which I prefer to do that 
> instead of  returning a deferred from the test case method.

Without language support, this is an exercise in futility.  Don't do it. 
  Trial is broken, and everyone laments it, but the *reason* that it's 
broken (the root cause, anyway, if not the only reason) is that it bends 
over backwards to accomodate this use-case when _every_ _other_ _part_ 
of Twisted is very explicit that this is a bad, bad thing to do and you 
should never do it because it doesn't work.

I am sorry that so many people want to block on deferreds in test 
methods, but I can guarantee you that support for doing it *WILL* be 
removed in a future version of Twisted.  If we don't eventually kill 
this feature, our test suite is never going to work reliably.




More information about the Twisted-Python mailing list