Skip to content
Discussion options

You must be logged in to vote

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:

@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, letter

Any test using combined will run with:

(1, "a")
(1, "b")
(2, "a")
(2, "b")

Alternatively, if the pair conceptually belongs to one fixture:

import itertools
import pytest

@pytest.fixture(params=list(itertools.product([1, 2]…

Replies: 1 comment

Comment options

You must be logged in to vote
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
Category
Q&A
Labels
None yet
2 participants