[Twisted-Python] automated tests for a server application

Kyle Altendorf sda at fstab.net
Tue Nov 6 09:43:29 MST 2018



On 2018-11-06 11:28, Chris Withers wrote:
> On 06/11/2018 12:14, Kyle Altendorf wrote:
>> 
>> 
>> On November 6, 2018 6:41:23 AM EST, Chris Withers 
>> <chris at simplistix.co.uk> wrote:
>>> 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)

I guess I'm still not clear on what the point of using a 'fake' reactor 
over a 'real' one is.  Not that I'm an expert here...

> Nothing, but the technique could be used to install a fake reactor
> rather than having to change all the existing code to accept an
> optional reactor parameter.
> 
>> 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?
> 
> I'd love to see some good example of faking the data going through the
> connections, can you point me at some?


I would assume you would just write a 'client' in the test of whatever 
complexity (could just write hardcoded byte sequences) which opens a 
connection to the server and transmits the bytes and then asserts things 
about the response.  But no, I don't have any code.  I can't say I have 
a good test suite myself and I also don't actually use Twisted for 
internet stuff (canbus and serial).  Sorry.  I would expect the servers 
provided by Twisted would have their own tests you could look at though.

Cheers,
-kyle




More information about the Twisted-Python mailing list