title: AttributeError when using request.function in pytest yield fixture
body: <p>I have several pytest test cases that need nearly identical setup, so I would like to have them reuse a fixture to keep things DRY. The setup involves creating a new ticket in an external ticket tracking system, then the test cases interact with the ticket based on the data, and finally the fixture cleans up by closing out the ticket. The challenge here is that each test case needs slightly different data to be prepped in the ticket.</p>
  
  <p>Each test case has different calls and different assertions, so I can't combine them all into a single parametrized test case with a single test fixture. Parametrizing the the fixture itself would result in every test case running every permutation of the fixture data, which ends up with a lot of irrelevant test failures.</p>
  
  <p>What I would like to do is set a variable in the test case, then have the fixture use that variable to set up the test data when creating the ticket. I've tried to use <code>request.function</code> as specified in the <a href="http://doc.pytest.org/en/latest/builtin.html#_pytest.python.FixtureRequest.function" rel="nofollow noreferrer">pytest fixture docs</a> but I keep getting:</p>
  
  <pre><code>=================================== ERRORS ===================================
      ____________________ ERROR at setup of TestMCVE.test_stuff ___________________
  
  request = &lt;SubRequest 'ticket' for &lt;Function 'test_stuff'&gt;&gt;
  
      @pytest.yield_fixture
      def ticket(request):
  &gt;       ticket_summary = getattr(request.function, "summary")
  E       AttributeError: 'function' object has no attribute 'summary'
  
  tests\test_mcve.py:11: AttributeError
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>import pytest
  
  
  def ticket_system_api(summary):
      # stub for MCVE purposes
      return summary
  
  
  @pytest.yield_fixture
  def ticket(request):
      ticket_summary = getattr(request.function, "summary")
      new_ticket = ticket_system_api(summary=ticket_summary)
      yield new_ticket
  
  
  class TestMCVE:
      def test_stuff(self, ticket):
          summary = 'xyz'
          # do real things here, except MCVE
          assert 'xyz' == ticket
  </code></pre>
  
  <p>I've tried using <code>request.node</code> instead of <code>request.function</code> as well as <a href="https://stackoverflow.com/questions/33548835/pytest-fixture-introspect-on-function-level">binding the summary variable per this answer</a>, changing <code>summary = 'xyz'</code> to <code>test_stuff.summary = 'xyz'</code> but these still fail with the same AttributeError.</p>
  
  <p>How can I pass the function level data to the fixture?</p>