<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
I have a class that looks something like this:<br>
<br>
<code>class FooListener(object):<br>
&nbsp;&nbsp;&nbsp; def __init__(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>
<br>
&nbsp;&nbsp;&nbsp; @inlineCallbacks<br>
&nbsp;&nbsp;&nbsp; def fooBar():<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try:<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yield doSomeSetup()<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; doSomethingThatReturnsADeferred()<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; returnValue('success!')<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; except:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; returnValue('failure!')<br>
<br>
</code>Note that doSomethingThatReturnsADeferred() has no callbacks.<br>
<br>
I also have a unit test that looks something like this:<br>
<br>
<code>def TestFoo(unittest.TestCase):<br>
&nbsp;&nbsp;&nbsp; def setUp(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeout = 1000000<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.listener = FooListener()<br>
<br>
&nbsp;&nbsp;&nbsp; @inlineCallbacks<br>
&nbsp;&nbsp;&nbsp; def testFooBar(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yield self.listener.fooBar()<br>
</code><br>
When I run this, I get this error:<br>
<br>
<samp>[ERROR]: foo.TestFoo.testFooBar<br>
<br>
Traceback (most recent call last):<br>
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was
unclean.<br>
Selectables:<br>
&lt;twisted.internet.process.ProcessWriter object at 0x3b7b650&gt;<br>
-------------------------------------------------------------------------------<br>
Ran 1 tests in 9.028s<br>
<br>
FAILED (errors=1, successes=1)<br>
</samp><br>
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. :-)<br>
<br>
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. <br>
<br>
Is there a way to instruct Trial to "wait" for Deferreds to fire?<br>
<br>
thanks<br>
<pre class="moz-signature" cols="72">-- 
Mark Visser, Software Director
Lumi&egrave;re VFX
Email: <a class="moz-txt-link-abbreviated" href="mailto:markv@lumierevfx.com">markv@lumierevfx.com</a>
Phone: +1-514-316-1080 x3030
</pre>
</body>
</html>