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

Antoine Pitrou antoine.pitrou at wengo.com
Wed Feb 7 12:36:15 EST 2007


Hi,

Le mercredi 07 février 2007 à 16:35 +0000, glyph at divmod.com a écrit :
> Yes.  Also, it's highly likely that the tests won't stop cleanly on
> ^C.

Depends on what you mean by "cleanly". I haven't noticed any annoying
behaviour when killing tests in the middle.

Regardless of ^C, there is a sporadic exception at shutdown due to the
way Python destroys modules (it first sets the module members to None).
I suppose it can happen in any situation in which Twisted is run in a
separate thread:

<<
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "threading.py", line 460, in __bootstrap
  File "threading.py", line 440, in run
  File "/home/antoine/nose-svn/nose/twistedtools.py", line 52, in <lambda>
  File "/usr/lib/python2.5/site-packages/twisted/internet/posixbase.py", line 218, in run
  File "/usr/lib/python2.5/site-packages/twisted/internet/posixbase.py", line 231, in mainLoop
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'msg'
Unhandled exception in thread started by 
Error in sys.excepthook:

Original exception was:
>>

> More serious than the process-running issue, from my point of view, is
> the fact that if you forget the "@deferred" decorator on a test that
> uses any reactor API, or code that internally _uses_ any reactor API,
> you will put your tests into a non-deterministic state, and although
> they'll pass _most_ of the time, they will die depending on the load
> characteristics of your machine at the time and (insert long-winded
> rant about the evil things threads do to your code here).  Tests are
> exactly the place you never want this to happen :).

That's certainly right, although you should get messages about uncaught
exceptions or unhandled errbacks, so you'll know that something went
wrong.
What happens with Trial when you forget to return the Deferred the test
should wait on?

> Also, setUp and tearDown methods also need the decorator applied, I
> think, not just test methods.

Setup methods at least, if they do something asynchronous.

> All in all it seems like it would be simpler to just use trials'
> TestCase class with nose.  Is there any reason not to?

Given that Trial is a self-contained tool, and given that nose also has
its own test running and collecting, I simply didn't expect this to work
or to keep working accross versions of both tools.

> Trial doesn't force your code to make use of Twisted, and as Mr. Lange
> has declared previously, it goes to some lengths to be compatible with
> stdlib unit tests.

Of course, but to use Trial you must install Twisted don't you ?
Which is quite a big dependency, and Twisted does not yet support being
easy_install'ed.

Regards

Antoine.






More information about the Twisted-Python mailing list