title: Pytest yield fixture usage
body: <p>I have a use case where I may use fixture multiple times inside a test in a "context manager" way.  See example code below:</p>
  
  <p>in conftest.py</p>
  
  <pre><code>class SomeYield(object):
      def __enter__(self):
          log.info("SomeYield.__enter__")
  
      def __exit__(self, exc_type, exc_val, exc_tb):
          log.info("SomeYield.__exit__")
  
  
  def generate_name():
      name = "{current_time}-{uuid}".format(
          current_time=datetime.now().strftime("%Y-%m-%d-%H-%M-%S"),
          uuid=str(uuid.uuid4())[:4]
      )
      return name
  
  
  @pytest.yield_fixture
  def some_yield():
      name = generate_name()
      log.info("Start: {}".format(name))
      yield SomeYield()
      log.info("End: {}".format(name))
  </code></pre>
  
  <p>in test_some_yield.py</p>
  
  <pre><code>def test_some_yield(some_yield):
      with some_yield:
          pass
  
      with some_yield:
          pass
  </code></pre>
  
  <p>Console output:</p>
  
  <pre><code>INFO:conftest:Start: 2017-12-06-01-50-32-5213
  INFO:conftest:SomeYield.__enter__
  INFO:conftest:SomeYield.__exit__
  INFO:conftest:SomeYield.__enter__
  INFO:conftest:SomeYield.__exit__
  INFO:conftest:End: 2017-12-06-01-50-32-5213
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>If I have some setup code in SomeYield.<strong>enter</strong> and cleanup code in
  SomeYield.<strong>exit</strong>, is this the right way to do it using fixture for
  multiple calls in my test? </li>
  <li>Why didn't I see three occurrences of
  <strong>enter</strong> and <strong>exit</strong>?  Is this expected?</li>
  </ol>