title: Can I pass arguments to pytest fixtures?
body: <p>The baseline of all my tests is that there will always be a taxi with at least one passenger in it. I can easily achieve this setup with some basic fixtures:</p>
  
  <pre><code>from blah import Passenger, Taxi
  
  @pytest.fixture
  def passenger():
      return Passenger()
  
  @pytest.fixture
  def taxi(passenger):
      return Taxi(rear_seat=passenger)
  </code></pre>
  
  <p>Testing the baseline is straightforward:</p>
  
  <pre><code>def test_taxi_contains_passenger(taxi)
      assert taxi.has_passenger()
  </code></pre>
  
  <p>My issue crops up when I start needing more complicated test setup. There will be scenarios where I'll need the taxi to have more than one passenger and scenarios where I'll need to define passenger attributes. For example:</p>
  
  <pre><code>def test_three_passengers_in_taxi(taxi)
      assert taxi.has_passengers(3)
      assert taxi.front_passenger_is_not_a_child()
  </code></pre>
  
  <p>I'm able to get around this problem by having specific fixtures for specific tests. For the above test, I would create the following fixture:</p>
  
  <pre><code>@pytest.fixture
  def three_passenger_test_setup(taxi)
      taxi.add_front_seat_passenger(Passenger(child=False))
      taxi.add_rear_seat_passenger(Passenger())
      return taxi
  </code></pre>
  
  <p>I can pass the above fixture into my test case and everything is dandy, but if I go down this route I might end up with a fixture for every test and it feels like there should be a more efficient way of doing this.</p>
  
  <p>Is there a way to pass arguments to a fixture so that those arguments can be used in creating the object the fixture returns? Should I be parameterizing the test function? The fixture? Or am I wasting time and is a fixture per test the way to go?</p>