tearDown not called after timeout in twisted trial?
<p>I'm seeing an issue in my test suite in trial where everything works fine until I get a timeout. If a test fails due to a timeout, the tearDown function never gets called, leaving the reactor unclean which in turn causes the rest of the tests to fail. I believe tearDown should be called after a timeout, does anyone know why this might happen?</p>

<p>It's rather strange because on my box, the teardown executes even if a timeout occurs. The tests should stop running if the reactor is not in a clean state, unless you use the <code>--unclean-warnings</code> flag. Does the test runner stop after the timeout for you? What version of Python and Twisted are you running?</p>

<p>As a side note, if you need to run a unique teardown for a specific test function, there's a very convenient <a href="https://twistedmatrix.com/documents/current/core/howto/trial.html#cleaning-up-after-tests" rel="nofollow"><code>addCleanup()</code></a> callback. It comes in handy if you need to cancel callback, LoopingCall, or callLater functions so that the reactor isn't in a dirty state. <code>addCleanup</code> returns a <code>Deferred</code> so you can just chain callbacks that perform an adhoc teardown. It might be a good option to try if the class teardown isn't working for you.</p>

<p>PS</p>

<p>I've been so used to writing "well behaved" Twisted code, I don't even recall how to get into an unclean reactor state :D I swear I'm not bragging. Could you provide me a brief summary of what you're doing so that I could test it out on my end?</p>

python testing twisted trial