[Twisted-Python] Help with Simple Trial unit test

Jean-Paul Calderone exarkun at divmod.com
Wed Jan 30 15:01:34 MST 2008


On Wed, 30 Jan 2008 13:45:08 -0800 (PST), Shawn Smiley <ssmiley483 at yahoo.com> wrote:
>Hi all,
>
>I recently started learning Python & Twisted in prep for a big project at work.  So far things are going well, except that I can't quite figure out what I'm doing wrong in this simple unit test I'm writing.
>
>One of the features of the project I'll be working on is the implementation of a simple HTTP GET Based communication layer between legacy systems.  As such, I wanted to write a simple unit test that uses the twisted client.getPage() method to test the communication process (i.e. simulates a legacy system requesting data from the server).
>
>I have a test that sort of works.  However, I find that I have to add a reactor.run() command in the unit test for the test to actually be executed.  The unfortunate side affect of this is that you then have to ctrl+C to stop the reactor after the test runs.  If I don't put in the reactor.run() command, I get a "REACTOR UNCLEAN" error message and the test doesn't appear to run (at least the callbacks from getPage() never happen).

What happens if you take the Deferred created in the test method and return
it, instead of calling reactor.run()?

Jean-Paul




More information about the Twisted-Python mailing list