[Twisted-Python] Testing Twisted code without trial

Itamar Turner-Trauring itamar at itamarst.org
Tue Mar 26 07:40:23 EDT 2013

On 03/26/2013 06:39 AM, Adi Roiban wrote:
> I am "spining" the reactor to "resolve" all deferreds involved in a
> StringTransport conversation or in an DeferredList or other kind of
> chained deferreds. These are what I call "integration tests" and they
> only use memory, no external I/O.
If you're only using StringTransport or Clock, there is no need for a 
real reactor. Deferreds have nothing to do with the reactor as such.

> In most of my calles of result = self.getDeferredResult(deferred), the
> deferred's callback() method was already called and I just want to
> resolve the callbacks chain.

Again, that does not require the reactor. E.g.:

 >>> d = Deferred()
 >>> d.callback(1)
 >>> l = []
 >>> d.addCallback(l.append)
 >>> l

You might also want to look at the latest version of 
http://twistedmatrix.com/documents/current/core/howto/trial.html, in 
particular the new successResultOf and similar APIs.

More information about the Twisted-Python mailing list