[Twisted-Python] Automatic test for Twisted

Reza Lotun rlotun at gmail.com
Fri May 29 08:04:12 EDT 2009

On Fri, May 29, 2009 at 3:01 AM, David Ripton <dripton at ripton.net> wrote:
> Another option is nose.  Google for "nose.twistedtools"

I've used nose for twisted unittests - and it usually works fine for
my purposes.

Just to expand a bit on how *I've* used it:

from nose.twistedtools import deferred
from twisted.internet import defer

def test_something():
   res = yield func_that_returns_deferred()
   assert res == 'something'


It's generally quite readable, and integrates nicely with non-twisted
unittests - I like the way that you can just write 'asserts'. However,
there are some caveats - namely that twisted is actually started in
another thread. So, if you plan to run a server to test calls against
(say in your setup_module) you need to make a wrapper around any
connection maker to use reactor.callFromThread.

Hope that's useful,

Reza Lotun
+44 (0)7521 310 763
rlotun at gmail.com

More information about the Twisted-Python mailing list