0

I'm trying to create a fixture that has dependencies on other fixtures and is also parameterized. Example:

@pytest.fixture(scope="module")
def fix1():
  ...

@pytest.fixture(scope="module", params=[False, True])
def fix2(fix1, param):
  ...

which gives me the error: fixture 'param' not found.

I've tried using a default arg

@pytest.fixture(scope="module", params=[False, True])
def fix2(fix1, param=True):
  ...

but this just ends up with the fixture always receiving True no matter the parameter. @pytest.mark.parameterize(..., indirect=True) on the test also just ends up with the same result as the above.

1 Answers1

0

You need to use request as the fixture function's argument, and then its property param to get the value:

@pytest.fixture(scope="module", params=[False, True])
def fix2(fix1, request):
    print(request.param)
    ...
tmt
  • 7,611
  • 4
  • 32
  • 46