Alex Rivera | Logout

Python - Twisted and Unit Tests

Asked 2009-10-16T01:03:08.260
20

I'm writing unit tests for a portion of an application that runs as an HTTP server. The approach I have been trying to take is to import the module that contains the HTTP server, start it. Then, the unit tests will use urllib2 to connect, send data, and check the response.

Our HTTP server is using Twisted. One problem here is that I'm just not that familiar with Twisted :)

Now, I instantiate our HTTP server and start it in the setUp() method and then I stop it in the tearDown() method.

Problem is, Twisted doesn't appear to like this, and it will only run one unit test. After the first one, the reactor won't start anymore.

I've searched and searched and searched, and I just can't seem to find an answer that makes sense.

Am I taking the wrong approach entirely, or just missing something obvious?

Edit
Report

1 Answer

7

I believe that for unit testing within Twisted you're supposed to use TwistedTrial (it's a core component, i.e., comes with the Twisted tarball in the twisted/trial directory). However, as the URL I've pointed to says, the doc is mostly by having a look through the source (including sources of various Twisted projects, as they're tested with Trial too).

answered 2009-10-16T01:09:02.527

Your Answer