title: How to parametrize a Pytest fixture
body: <p>Consider the following Pytest:</p>
  
  <pre><code>import pytest
  
  class TimeLine(object):
      instances = [0, 1, 2]
  
  @pytest.fixture
  def timeline():
      return TimeLine()
  
  def test_timeline(timeline):
      for instance in timeline.instances:
          assert instance % 2 == 0
  
  if __name__ == "__main__":
      pytest.main([__file__])
  </code></pre>
  
  <p>The test <code>test_timeline</code> uses a Pytest fixture, <code>timeline</code>, which itself has the attribute <code>instances</code>. This attribute is iterated over in the test, so that the test only passes if the assertion holds for every <code>instance</code> in <code>timeline.instances</code>.</p>
  
  <p>What I actually would like to do, however, is to generate 3 tests, 2 of which should pass and 1 of which would fail. I've tried</p>
  
  <pre><code>@pytest.mark.parametrize("instance", timeline.instances)
  def test_timeline(timeline):
      assert instance % 2 == 0
  </code></pre>
  
  <p>but this leads to </p>
  
  <pre><code>AttributeError: 'function' object has no attribute 'instances'
  </code></pre>
  
  <p>As I understand it, in Pytest fixtures the function 'becomes' its return value, but this seems to not have happened yet at the time the test is parametrized. How can I set up the test in the desired fashion?</p>