From smarie/python-pytest-cases#36
This works:
@pytest.fixture(params=['a', 'b'])
def arg(request):
return request.param
@pytest.mark.parametrize("arg", [1])
def test_reference(arg, request):
assert '[1]' in request.node.nodeid
the arg parameter in the test correctly hides the arg fixture so the unique pytest node has id [1] (instead of there being two nodes because of the fixture).
However if the fixture that is hidden by the parameter depends on another fixture, that other fixture is mistakenly kept in the fixtures closure, even if it is not needed anymore. Therefore the test fails:
@pytest.fixture(params=['a', 'b'])
def argroot(request):
return request.param
@pytest.fixture
def arg(argroot):
return argroot
@pytest.mark.parametrize("arg", [1])
def test_reference(arg, request):
assert '[1]' in request.node.nodeid