title: pytest -- how do I use global / session-wide fixtures?
body: <p>I want to have a "global fixture" (in pytest they could also be called "session scoped fixtures") which does some expensive environment setup, like typically preparing a resource, which is then reused across test modules. The setup is something like this,</p>
  
  <h3>shared_env.py</h3>
  
  <p>would have a fixture doing something expensive, like starting up a Docker container, MySQL server, etc.</p>
  
  <pre><code>@pytest.yield_fixture(scope="session")
  def test_server():
      start_docker_container(port=TEST_PORT)
      yield TEST_PORT
      stop_docker_container()
  </code></pre>
  
  <h3>test_a.py</h3>
  
  <p>would use the server,</p>
  
  <pre><code>def test_foo(test_server): ...
  </code></pre>
  
  <h3>test_b.py</h3>
  
  <p>would use the same server</p>
  
  <pre><code>def test_foo(test_server): ...
  </code></pre>
  
  <p>It seems that pytest has support for this via <code>scope="session"</code>, but I can't figure out how to make the actual imports work. The current setup will given an error message like,</p>
  
  <pre><code>fixture 'test_server' not found
  available fixtures: pytestconfig, ...
  use 'py.test --fixtures [testpath] ' for help on them
  </code></pre>