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>You are correct that <code>tearDown()</code> should be called regardless of what happens in your test. From <a href="https://docs.python.org/2/library/unittest.html#unittest.TestCase.tearDown" rel="nofollow">the documentation</a> for <code>tearDown()</code>:</p>

<blockquote>
  <p>This is called even if the test method raised an exception</p>
</blockquote>

<p>However, there is a catch. From the same documentation:</p>

<blockquote>
  <p>This method will only be called if the setUp() succeeds, regardless of the outcome of the test method.</p>
</blockquote>

<p>So it sounds like you perhaps start the reactor in <code>setUp()</code> and when it times out, this is preventing your <code>tearDown()</code> from running - the idea being that whatever you were trying to "set up" in <code>setUp()</code> was <em>not</em> successfully set up, so you do not want to try to tear it down. However, it would be hard to diagnose with certainty unless you provide the code of your <code>setUp</code> and <code>tearDown</code> methods, along with the code of any relevant tests. </p>

python testing twisted trial