title: Creating a temporary directory in PyTest
body: <p>My Python project imports <code>pytest</code> 2.9.0 fine without any issues.</p>
  
  <p>I want to create a new empty directory that will last only the life of the test session. I see that pytest offers temporary directory support:</p>
  
  <p><a href="https://pytest.org/latest/tmpdir.html" rel="noreferrer">https://pytest.org/latest/tmpdir.html</a></p>
  
  <blockquote>
    <p>You can use the tmpdir fixture which will provide a temporary directory unique to the test invocation, created in the base temporary directory.  </p>
    
    <p>tmpdir is a py.path.local object which offers os.path methods and more. Here is an example test usage:</p>
  </blockquote>
  
  <p>The source-code for pytest shows that <code>def tmpdir</code> is a global/module function: <a href="https://pytest.org/latest/_modules/_pytest/tmpdir.html" rel="noreferrer">https://pytest.org/latest/_modules/_pytest/tmpdir.html</a></p>
  
  <p>However my test file fails:</p>
  
  <pre><code>import pytest
  
  # ...
  
  def test_foo():
      p = pytest.tmpdir()
  </code></pre>
  
  <p>With error:</p>
  
  <blockquote>
    <p>AttributeError: 'module' object has no attribute 'tmpdir'</p>
  </blockquote>
  
  <p>Doing <code>from pytest import tmpdir</code> fails with:</p>
  
  <blockquote>
    <p>ImportError: cannot import name tmpdir</p>
  </blockquote>