[Twisted-Python] Stopping Reactor in UnitTest Callback

Itamar Turner-Trauring itamar at futurefoundries.com
Sat Jan 12 18:31:13 EST 2013

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

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20130112/261e8a5b/attachment.htm 

More information about the Twisted-Python mailing list