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

Alessio Pace alessio.pace at gmail.com
Mon Jan 26 08:00:18 EST 2009


On Mon, Jan 26, 2009 at 12:09 PM, Drew Smathers <drew.smathers at gmail.com>wrote:

> 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.


The point is that I must assure multiple test classes have their test
methods run within an active reactor. So somewhere a reactor.run() has to be
called.. Necessarily, if I want that my tests battery to terminate, a
reactor.stop() must be invoked by somebody, otherwise the main loop remains
running...

The trivial -and not working- idea was to do reactor.run() / reactor.stop()
in setUp() / tearDown() methods.

I believe extening Trial TestCase is the good way to go, but as you are
mentioning, there is not so much documentation... I'm trying to understand
how to do from the UDP test case in Twisted trunk..

Thanks. Regards,
Alessio Pace.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090126/e9d77cab/attachment.htm 


More information about the Twisted-Python mailing list