[Twisted-Python] the right way of unit testing protocols

Andrew Bennetts andrew-twisted at puzzling.org
Wed Jul 30 22:09:00 EDT 2003

On Wed, Jul 30, 2003 at 03:10:39PM -0400, Itamar Shtull-Trauring wrote:
> On Thu, 31 Jul 2003 00:26:07 +0530
> Jeethu Rao <jeethur at sancharnet.in> wrote:
> > I know that I can setup two reactors, for the client and the server
> > and then try to make them talk, But I'm sure there's a shortcut.
> > I just could'nt figure out the test suites from the Twisted sources.
> You only need one reactor. (And twisted doesn't support multiple
> reactors at the moment anyway.) So don't look for that in the code. Just
> look at how the tests are done.
> In general you'd just do some variant on:
>  reactor.listenTCP(1234, myServerFactory)
>  reactor.connectTCP("", 1234, myClientFactory):
>  while someConditionIsn'tSet:
>      reactor.iterate()
>  # at this point some exchange should have finished successfully

Or you can use the loopback module -- twisted.protocols.loopback.  Many of
the Twisted tests do this.


More information about the Twisted-Python mailing list