Different collection order if parametrized fixture is not function-scoped #13300
Answered
by
RonnyPfannschmidt
chbndrhnns
asked this question in
Q&A
-
I noticed an interesting behaviour when running this test module. import pytest
@pytest.fixture(
scope="class",
# scope="function",
params=["param1", "param2"],
)
def f(request):
return request.param
def test_one(f):
assert f
def test_two(f):
assert f Using a function-scoped fixture, pytest orders the test list by functions:
When changing the scope to "class" or higher, pytest orders the test list by parameters:
Is this somehow expected? |
Beta Was this translation helpful? Give feedback.
Answered by
RonnyPfannschmidt
Mar 15, 2025
Replies: 1 comment
-
Yes pytest is reordering tests to minimize the number of times higher scope fixtures have to be setup/ teardown |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
chbndrhnns
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes pytest is reordering tests to minimize the number of times higher scope fixtures have to be setup/ teardown