[Twisted-Python] Stopping Reactor in UnitTest Callback

Fabian Rothfuchs fabian.rothfuchs at googlemail.com
Tue Jan 15 10:26:19 EST 2013

Yes, I thought so, too. Indeed it happens that the reactor is started
automatically, but after the test succeeds, it's not being stopped (only
chance is to kill ­9 it).
I'm afraid I need to use the reactor, as I'd like to make automatic
end-to-end tests within my application, going from the workflow until a
dummy server, returning the data that was sent by the protocol back to the

From:  Itamar Turner-Trauring <itamar at futurefoundries.com>
Reply-To:  Twisted general discussion <twisted-python at twistedmatrix.com>
Date:  Sunday, January 13, 2013 12:31 AM
To:  Twisted general discussion <twisted-python at twistedmatrix.com>
Subject:  Re: [Twisted-Python] Stopping Reactor in UnitTest Callback

On Sat, Jan 12, 2013 at 9:00 AM, Fabian Rothfuchs
<fabian.rothfuchs at googlemail.com> wrote:
> I'm in the dilemma of using both - Django and Twisted.
> My goal is to have Django initialising the test (python manage.py test
> <appname>), instead of trial, as it will setup the whole test environment
> (I.e. Creates a db copy, allows per-model testing, follows certain
> conventions, etc).
> As to that I'm trying to find a way how to start/stop the reactor from the
> test, as trial is not executed.
> Do you have an idea or an approach how this could be realised?

The functionality to start/stop the reactor when a test returns a Deferred
is part of twisted.trial.unittest.TestCase, which subclasses Python's
unittest.TestCase. As a result you don't need to use the trial command-line
tool, you can use any Python test runner that knows about Python's TestCase;
just make sure to subclass twisted.trial.unittest.TestCase, and your test
will support running the reactor for you when you return a Deferred.

Or, if possible, you can avoid using the reactor at all; some approaches (as
mentioned by Jean-Paul) are described in the trial documentation:

Itamar Turner-Trauring, Future Foundries LLC
http://futurefoundries.com/ ‹ Twisted consulting, training and support.
_______________________________________________ Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20130115/a325f34f/attachment.htm 

More information about the Twisted-Python mailing list