[Twisted-Python] Stopping Reactor in UnitTest Callback

Fabian Rothfuchs fabian.rothfuchs at googlemail.com
Sat Jan 12 07:00:17 MST 2013


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?

Thanks
Fabian


On 1/10/13 9:51 PM, "exarkun at twistedmatrix.com"
<exarkun at twistedmatrix.com> wrote:

>On 07:58 pm, fabian.rothfuchs at googlemail.com wrote:
>>Hey there,
>>
>>
>>I'm trying to start and stop a twisted server in a unittest:
>>http://dpaste.org/qwaUt/ .
>
>Why?  This isn't the typical way to write unit tests for Twisted-based
>code.  The reactor is started and stopped by trial as necessary.  Your
>code should just expect that it is running and let trial stop it when it
>is time to stop.
>
>If you have asynchronous code to test, you return a Deferred from a test
>method and the test completes when the Deferred fires.  Not when the
>reactor stops.
>
>Also, a lot of people have come to dislike this style of test, instead
>preferring to use test doubles that don't involve real I/O or time so
>that they can completely test the logic of their code deterministically
>- thus also without ever running a real reactor or needing to use the
>"return a Deferred from a test method" feature of trial.
>
>Jean-Paul
>
>_______________________________________________
>Twisted-Python mailing list
>Twisted-Python at twistedmatrix.com
>http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python






More information about the Twisted-Python mailing list