title: Repeated use of fixtures in pytest
body: <p>I am learning pytest, particularly its fixtures which are different from the xUnit setUp() and tearDown() paradigm. Say I have the following test:</p>
  
  <pre><code>import pytest
  
  
  @pytest.fixture()
  def foo():
      return 'foo'
  
  
  @pytest.fixture()
  def bar():
      return 'bar'
  
  
  @pytest.fixture()
  def baz():
      return 'baz'
  
  
  @pytest.fixture()
  def foobar(foo, bar):
      return foo + bar
  
  
  @pytest.fixture()
  def foobaz(foo, baz):
      return foo + baz
  
  
  def test(foobar, foobaz):
      print('test')
      print(foobar)
      print(foobaz)
  </code></pre>
  
  <p>In this example, the <code>foo()</code> fixture is used twice, once by <code>foobar()</code> and again by <code>foobaz()</code>. If I reuse the same fixture multiple times for a single test, is the fixture function called once and its result cached? Or is it called each time that it is used? In my contrived example, the returned value is static, so there is no problems. I can imagine many situations where the returned value is more dynamic and I need to guarantee that I have the exact same instance everywhere it is used.</p>