title: pytest: full cleanup between tests
body: <p>In a module, I have two tests:</p>
  <pre class="lang-py prettyprint-override"><code>@pytest.fixture
  def myfixture(request):
      prepare_stuff()
      yield 1
      clean_stuff()
      # time.sleep(10) # in doubt, I tried that, did not help
  
  def test_1(myfixture):
      a = somecode()
      assert a==1
  
  def test_2(myfixture):
      b = somecode()
      assert b==1
  </code></pre>
  <h3>case 1</h3>
  <p>When these two tests are executed individually, all is ok, i.e. both</p>
  <pre class="lang-sh prettyprint-override"><code>pytest ./test_module.py:test_1
  </code></pre>
  <p>and immediately after:</p>
  <pre class="lang-sh prettyprint-override"><code>pytest ./test_module.py:test_2
  </code></pre>
  <p>run until completion and pass with success.</p>
  <h3>case 2</h3>
  <p>But:</p>
  <pre class="lang-sh prettyprint-override"><code>pytest ./test_module.py -k &quot;test_1 or test_2&quot;
  </code></pre>
  <p>reports:</p>
  <pre><code>collected 2 items
  test_module.py .
  </code></pre>
  <p>and hangs forever (after investigation: <code>test_1</code> completed successfully, but the second call to <code>prepare_stuff</code> hangs).</p>
  <h3>question</h3>
  <p>In my specific setup <code>prepare_stuff</code>, <code>clean_stuff</code> and <code>somecode</code> are quite evolved, i.e. they create and delete some shared memory segments, which when done wrong can results in some hanging. So some issue here is possible.</p>
  <p>But my question is: are there things occurring between two calls of <code>pytest</code> (case 1) that do not occur between the call of <code>test_1</code> and <code>test_2</code> from the same &quot;pytest process&quot; (case 2), which could explain why &quot;case 1&quot; works ok while &quot;case 2&quot; hangs between <code>test_1</code> and <code>test_2</code> ?  If so, is there a way to &quot;force&quot; the same &quot;cleanup&quot; to occur between <code>test_1</code> and <code>test_2</code> for &quot;case 2&quot; ?</p>
  <p>Note: I already tried to specify the scope of &quot;myfixture&quot; to &quot;function&quot;, and also double checked that &quot;clean_stuff&quot; is called after &quot;test_1&quot;, even in &quot;case 2&quot;.</p>