title: How to get pytest fixture data dynamically
body: <p>I'm trying to define init data for several tests scenarios that test a single api endpoint.  I want to do this so that I don't have to produce boiler plate code for multiple iterations of a test where just the data differs. I can't seem to wrap my head around how to do this using the built-in pytest fixtures.  Here's essentially what I'm trying to do:</p>
  
  <p>In tests/conftext.py:</p>
  
  <pre><code>import pytest
  
  @pytest.fixture(scope="module")
  def data_for_a():
      return "a_data"
  
  @pytest.fixture(scope="module")
  def data_for_b():
      return "b_data"
  </code></pre>
  
  <p>In tests/tests.py</p>
  
  <pre><code>import pytest
  
  # this works
  def test_a(data_for_a):
      assert "a_data" == data_for_a
  
  # but I want to do this and it fails:
  scenarios = [
      { "name": "a", "data": data_for_a },
      { "name": "b", "data": data_for_b },
  ]
  
  for scenario in scenarios:
      print(scenario.name, scenario.data)
  
  # desired output:
  # "a a_data"
  # "b b_data"
  </code></pre>
  
  <p>I get a <code>NameError: name 'data_for_a' is not defined</code> exception.  I've tried various approaches to get this to work, but there seems to be no way around having to pass the fixture as a parameter to the test method - so either define a bunch of boilerplate tests or have a bunch of if/else statements in a single test and pass each fixture explicitly.  I don't like either of these options.  At the moment it seems like I have to just build my own helper module to pull in this test data, but I'd rather use the built-in mechanism for this.  Is there any way to do this?</p>