Skip to content
Discussion options

You must be logged in to vote

Thanks for the additional context. A parametrized fixture only has one parameter slot: the fixture itself. Each entry in params becomes the single value exposed as request.param.

So this does not work:

@pytest.fixture(params=[pytest.param(i, 5) for i in range(5)])

because pytest.param(i, 5) creates a parameter set containing two values, while the fixture parametrization expects one.

If the intended fixture value is the pair (i, 5), make that pair the single parameter:

@pytest.fixture(params=[pytest.param((i, 5)) for i in range(5)])
def my_fixture(request):
    return request.param

or simply:

@pytest.fixture(params=[(i, 5) for i in range(5)])
def my_fixture(request):
    return request.param

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@DavideCanton
Comment options

@portyu9
Comment options

Answer selected by DavideCanton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants