[Twisted-Python] Re: Using twisted.trial with nose unittest system

Jean-Paul Calderone exarkun at divmod.com
Wed Feb 7 10:06:12 EST 2007


On Wed, 07 Feb 2007 12:46:14 +0100, Antoine Pitrou <antoine.pitrou at wengo.com> wrote:
>
>Hi,
>
>> I spent some more time investigating this today and found that someone
>> has written a plugin for nose that allows it to test twisted code.  I
>> don't think it looks as nice as trial, but it should work for the
>> basics.    You can see it here:
>> http://python-nose.googlecode.com/svn/trunk/nose/twistedtools.py
>>
>> If I run into some serious issues I will try my best to extend this
>> plugin to support additional capabilities from trial.
>
>Since I'm the author of this "plugin" (just a module actually) your
>remarks are very welcome.
>
>> > def threaded_reactor():
>>
>> Yep.  Not pretty by any means. :(
>
>Oh, certainly not less pretty than the self-admitted hacks that trial
>uses (e.g. to stop/restart the reactor).

I don't think anyone will claim trial doesn't have more than its fair
share of terrifying hacks. :)  I hope that trial isn't being used as
a standard of quality for other coding endeavours.

>
>My "not pretty" solution has something like 50 lines of actual code and
>only uses official Twisted features, which makes its complexity very
>manageable. Compare that to Trial.

We could do that, but it seems a little silly.  There's a lot more to
trial than just reactor cooperation.  Anyway, I'm not so interested in
this point.

>
>I'm open to any suggestion for not making use of a separate thread but,
>until Twisted officially supports stopping and restarting the reactor, I
>don't think it's possible (without using any of trial's self-admitted
>hacks).

That would probably involve more knowledge of nose implementation details
than I have right now, or I'd try to offer some.  I'm sure if it were a
simple matter to get things working nicely, you would have done that. :)

>
>However, I'm not interested in grandiloquent rants about "Threads are
>Evil" (I've already read them :-)).

The one practical problem which this method of integration has is that
it will not allow unit tests to run child processes.  So, one wouldn't
be able to run Twisted's test suite with nose using this.  Of course,
if one has no interest in running tests which run child processes, then
this may not be a big deal.

>
>> You never mentioned why nose interested you.  What's the attraction?
>
>Let me give a few points as for nose vs. Trial :
>- nose does not depend on Twisted. Unless all your Python projects make
>use of Twisted, you certainly don't like having to use a different
>testing tool depending on the project.
>- nose has nice features, including the ability to write tests as
>functions without having to write classes
>- nose has a plugin system which already provides several extensions
>- nose is documented
>

Thanks for the feature list. :)  The reason I posted to the thread is
that I was interested in which specific features were proving useful
to a real user.  Can I take this as a list of features you find to be
of practical value, as a user of nose yourself?

Jean-Paul




More information about the Twisted-Python mailing list