Repository navigation
Multiple parametrization of a fixture? #10534
Answered
by
portyu9
sadra-barikbin
asked this question in
Q&A
|
Is there a way to parametrize a fixture like we do by stacking |
Answered by
portyu9
Sep 9, 2026
Replies: 1 comment
|
You don't stack multiple If you want a Cartesian product, one clean approach is to make the parameters separate fixtures: @pytest.fixture(params=[1, 2])
def number(request):
return request.param
@pytest.fixture(params=["a", "b"])
def letter(request):
return request.param
@pytest.fixture
def combined(number, letter):
return number, letterAny test using Alternatively, if the pair conceptually belongs to one fixture: import itertools
import pytest
@pytest.fixture(params=list(itertools.product([1, 2], ["a", "b"])))
def combined(request):
return request.paramBoth produce the Cartesian-product behavior; the first form is usually nicer when the individual parameters are useful as fixtures themselves. Please mark this answer as accepted if it helped, thank you. |
0 replies
Answer selected by
sadra-barikbin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @sadra-barikbin
You don't stack multiple
@pytest.fixture(params=...)decorators in the same way that you can stack@pytest.mark.parametrize.If you want a Cartesian product, one clean approach is to make the parameters separate fixtures:
Any test using
combinedwill run with:Alternatively, if the pair conceptually belongs to one fixture: