title: How to get a pytest fixture interactively?
body: <p>How to import or otherwise bind a <code>pytest</code> fixture for interactive use, without using breakpoints?</p>
  
  <p>For example, I want to explore some behaviours of the <a href="https://docs.pytest.org/en/latest/tmpdir.html" rel="noreferrer"><code>tmpdir_factory</code></a> fixture in the REPL.  </p>
  
  <pre><code>from pytest import tmpdir_factory  # note: this doesn't actually work
  
  # setup / context has already been entered
  tmpdir_factory.ensure('exists.txt', file=True)  # I can use the fixture
  del tmpdir_factory  # teardown will eventually be called
  </code></pre>
  
  <p>In the case of <code>tmpdir</code> I already know it's just a <code>py.path.local</code> instance, but I'm interested in the general question for user defined fixtures too.  </p>
  
  <hr>
  
  <p><em>edit:</em> Another acceptable interface:</p>
  
  <pre><code>from magical_module import inject_fixture
  tmpdir_factory = inject_fixture('tmpdir_factory')
  </code></pre>
  
  <hr>
  
  <p><em>edit:</em> an MCVE to show whether context has exited or not:</p>
  
  <pre><code># conftest.py
  from datetime import datetime
  import pytest
  
  @pytest.fixture
  def my_fixture():
      obj = {'setup': datetime.now()}
      yield (obj, f'yielded @ {datetime.now()!r}')
      obj['teardown'] = datetime.now()
  </code></pre>