[Twisted-Python] Global reactor unit tests in the Twisted test suite

Phil Mayers p.mayers at imperial.ac.uk
Tue Nov 1 13:06:10 EDT 2011


On 01/11/11 16:58, Itamar Turner-Trauring wrote:
>> I find the "pass reactor as 1st argument to everything" API pattern
>> messy. I'm sure there's a good reason. What is it?
>
> 1. Supporting multiple reactors.

Interesting. I had assumed that was a "never on the cards" option. Would 
it be possible to "nest" the reactors, or would they have to run in 
separate threads? Or is this speculative?

>
> 2. Unit testing: if you have an explicit object, you can replace it more
> easily with a fake.

Ok. I realise it's a bit late in the day at this point, but I do wonder 
if something like:

def method(arg, reactor=DefaultReactor):
   ...

...with DefaultReactor being some kind of lazy singleton or weak 
reference might not have been a more friendly pattern to API users.

As it is, I might bind a keystroke to "reactor, " ;o)



More information about the Twisted-Python mailing list