[Twisted-Python] How to write (network) integration tests with Twisted?

Drew Smathers drew.smathers at gmail.com
Mon Jan 26 06:09:39 EST 2009

On Mon, Jan 26, 2009 at 4:02 PM, Alessio Pace <alessio.pace at gmail.com> wrote:
> Hi,
> I would like to put in my suite of tests some integration tests which deal
> with running some exchange of messages among 2 endpoints (bound locally on
> the same machine on 2 different ports).

Trial allows you to return a Deferred, which in you case is something
you would call after your endpoints close their connections.  You can
grep through twisted sources though to see how this can be done
without network connections in unit tests - look for test cases using
the module simio.

> I noticed (and read afterwards..) that I can't run()/stop() the reactor
> multiple times, so I was wondering what's the suggested way to deal with
> this kind of situation.

You can close connections and reconnect etc. without "restarting" the
reactor - so I don't see how this is an obstacle.

> Sorry if perhaps it is documented somewhere on the Twisted doc but apart
> from the mention to "Trial" (which I'm not sure responds to my needs) I
> haven't found much.

This isn't really documented. But again, unit tests for twisted itself
provide good examples.


More information about the Twisted-Python mailing list