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

Alessio Pace alessio.pace at gmail.com
Tue Jan 27 01:34:28 EST 2009

Hi all,

thanks your suggestions are very helpfull and I managed to have something
resembling an integration test using Trial :-)

Indeed the HTML version does not work for me either but the document still
remains helpfull. So, is this documentation something going to be published
sooner or later (as I see it's in a branch) ?

Thank you. Regards,
Alessio Pace

On Mon, Jan 26, 2009 at 6:00 PM, Martin Geisler <mg at daimi.au.dk> wrote:

> Alessio Pace <alessio.pace at gmail.com> writes:
> > 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).
> >
> > 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.
> >
> > 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.
> Trial is what you want, it knows how to deal with the Deferreds you are
> likely to return from your tests.
> The point is that you can do stuff like this where getPage is a function
> which returns a Deferred:
>  def test_something(self):
>    p = getPage("http://example.com/")
>    p.addCallback(self.assertEquals, "<html>...</html>")
>    return p
> When you return p from the test, the reactor will wait until p has fired
> before starting the next test. When p fires, the callbacks are executed
> like normal, and here the callsback compares the HTML retrieved with the
> expected content. If p does not fire within a given timeout (120 seconds
> by default, I think) the reactor will declare the test a failure.
> Take a look at the tutorial here:
> http://twistedmatrix.com/trac/browser/branches/trial-tutorial-2443/doc/core/howto/trial.xhtml
> Use the link for "Original Format" at the bottom to view as HTML, though
> I'm getting an XML parse error from my browser when I do this.
> I'm using the twisted.protocols.loopback module for connecting several
> parties with a pseudo-transport. This allows the testing code to behave
> like in your normal application, but the communication is done with
> function calls instead of actual network traffic.
> --
> Martin Geisler
> VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
> SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090127/590b4ffd/attachment.htm 

More information about the Twisted-Python mailing list