I have a class that looks something like this:

|class FooListener(object):
   def __init__(self):
       pass

   @inlineCallbacks
   def fooBar():
       try:
           yield doSomeSetup()
           doSomethingThatReturnsADeferred()
           returnValue('success!')
       except:
           returnValue('failure!')

|Note that doSomethingThatReturnsADeferred() has no callbacks.

I also have a unit test that looks something like this:

|def TestFoo(unittest.TestCase):
   def setUp(self):
       timeout = 1000000
       self.listener = FooListener()

   @inlineCallbacks
   def testFooBar(self):
       yield self.listener.fooBar()
|
When I run this, I get this error:

[ERROR]: foo.TestFoo.testFooBar

Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
Selectables:
<twisted.internet.process.ProcessWriter object at 0x3b7b650>
-------------------------------------------------------------------------------
Ran 1 tests in 9.028s

FAILED (errors=1, successes=1)

I'm clever enough to understand that Trial isn't waiting for the "backgrounded" Deferreds to fire, but I'm not clever enough to figure how to fix it. :-)

I could hack around this by passing a test_mode parameter to TestFoo.__init__ and "yield"-ing doSomethingThatReturnsADeferred(), but I'd rather not introduce special cases for testing.

Is there a way to instruct Trial to "wait" for Deferreds to fire?

thanks

--
Mark Visser, Software Director
Lumière VFX
Email: [email protected]
Phone: +1-514-316-1080 x3030

_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to