[Twisted-Python] automated tests for a server application
Kyle Altendorf
sda at fstab.net
Tue Nov 6 05:14:57 MST 2018
On November 6, 2018 6:41:23 AM EST, Chris Withers <chris at simplistix.co.uk> wrote:
>On 06/11/2018 05:43, Moshe Zadka wrote:
>>
>> Some of the best advice depends on details of the application. One
>> trick that is sometimes useful is passing in a "fake" reactor object.
>
>> This, of course, is only useful if the application is structured in a
>
>> way that functions/classes expect to get a reactor, instead of
>> reaching for the global one. However, usually *that's* not a
>> complicated refactoring to do.
>
>Cool, do you have any example tests that do this?
>Interesting, looks like pytest-twisted does away for the need for this
>by showing how to install a fake reactor globally:
>https://github.com/pytest-dev/pytest-twisted/blob/master/pytest_twisted.py#L129-L142
What is 'fake' about this globally installed normally-the-default reactor? (Otherwise the qt5reactor if chosen)
>> You can, of course, use a real reactor and a real client to pump
>data.
>> However, in that case, you probably do want to switch to trial so
>that
>> you can return a deferred from a test function and have the reactor
>> run until the deferred fires. This is not great, but can work in a
>pinch.
>
>pytest-twisted looks like it supports this pattern too, allowing test
>functions to return deferreds...
I use @pytest_twisted.inlineCallbacks anyways, yes.
Overall I'm not clear what was recommended here. Why fake the reactor? Even if not using a 'real client' wouldn't you just fake the data going through the connections rather than faking the entire reactor?
Cheers,
-kyle
More information about the Twisted-Python
mailing list