Reputation: 11763
Our Python code base uses nose to run all unit tests, and I'm trying to use nose.twistedtools to make all the tests run, but they're all hanging at shutdown. Any help straightening this out would be great. Here's a simple test that hangs:
from nose.twistedtools import deferred
from twisted.internet.defer import Deferred
@deferred(timeout=1)
def test_rudimentary():
def done(_ignored):
print "DONE"
defer = Deferred()
defer.addCallback(done)
return defer
The invocation and output looks like this:
$ nosetests test_simple.py
F
======================================================================
FAIL: test_simple.test_rudimentary
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/<ENV>/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/<ENV>/lib/python2.7/site-packages/nose/twistedtools.py", line 165, in wrapper
% timeout)
TimeExpired: timeout expired before end of test (1.000000 s.)
----------------------------------------------------------------------
Ran 1 test in 1.001s
FAILED (failures=1)
If I don't set a timeout, the test hangs forever.
Upvotes: 1
Views: 817
Reputation: 414079
Your code is responsible for calling defer.callback/errback (most probably indirectly). Try:
reactor.callLater(0.1, defer.callback)
return defer
Upvotes: 2