Skip to content

Cannot use pytest.mark.usefixtures() in pytest.param #4112

@dtomas

Description

@dtomas

Adding Fixtures to a parametrization of a test function via pytest.mark.usefixtures has no effect. The fixtures are not executed and are missing from request.fixturenames.

Example:

import pytest

@pytest.fixture
def c():
    return []

@pytest.fixture
def a(c):
    c.append('a')

@pytest.fixture
def b(c):
    c.append('b')

@pytest.mark.parametrize('expected', [
    pytest.param(['a'], marks=pytest.mark.usefixtures('a'), id='a'),
    pytest.param(['b'], marks=pytest.mark.usefixtures('b'), id='b'),
])
def test_usefixtures_param(request, c, expected):
    assert c == expected
$ pip list
Package        Version
-------------- -------
atomicwrites   1.2.1  
attrs          18.2.0 
more-itertools 4.3.0  
pip            18.1   
pluggy         0.7.1  
py             1.6.0  
pytest         3.8.2  
setuptools     40.4.3 
six            1.11.0 
wheel          0.32.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytopic: parametrizerelated to @pytest.mark.parametrizetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions