Skip to content

pytest.mark.parametrize does not correctly hide fixtures of the same name (it misses its dependencies) #5036

@smarie

Description

@smarie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions