You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pytest_generate_tests doesn't play with pytest.mark.parametrize #896
The fixture is called twice here, howerver it's a module scoped fixture so I expect only one call.
The bug doesn't occur when writting two tests instead of using pytest.mark.parametrize or when using @pytest.fixture(scope="module", param=["foo"] instead of pytest_generate_tests.
I've run into the same issue. I've found that it doesn't have to use both pytest_generate_tests and pytest.mark.parametrize. The issue comes about with any fixture that uses a parametrized parameter, along with another parametrized parameter being used in the same test function.
The following reproduces the above example but with using only pytest_generate_tests:
import pytest
CALL_COUNT = 0
def pytest_generate_tests(metafunc):
if "fixture_param" in metafunc.fixturenames:
metafunc.parametrize("fixture_param", ["foo"], scope="module")
if "test_param" in metafunc.fixturenames:
metafunc.parametrize("test_param", ["bar", "zaz"], scope="module")
@pytest.fixture(scope="module")
def fixture(fixture_param):
global CALL_COUNT
CALL_COUNT += 1
def test_1(fixture, test_param):
global CALL_COUNT
assert CALL_COUNT == 1
It looks like I am running into this issue too, which is causing my heavy setup/teardown to be run on each function instead of per session.
Is there any workaround for this?
Activity
Don't use pytest_generate_tests
RonnyPfannschmidt commentedon Sep 13, 2015
@philpep does this also happen when using indirect=True?
A-A-Ron-Diver commentedon Sep 16, 2015
I've run into the same issue. I've found that it doesn't have to use both
pytest_generate_testsandpytest.mark.parametrize. The issue comes about with any fixture that uses a parametrized parameter, along with another parametrized parameter being used in the same test function.The following reproduces the above example but with using only
pytest_generate_tests:bounceconnection commentedon Mar 7, 2016
I'm running into this issue as well, is there a workaround for this?
philpep commentedon Mar 28, 2016
@RonnyPfannschmidt indeed that doesn't occur with indirect=True
This test pass:
Stranger6667 commentedon Jul 26, 2016
Unfortunately #1766 didn't fix the issues here :(
RonnyPfannschmidt commentedon Jun 2, 2017
is a more extended example
jpsnyder commentedon Nov 8, 2021
It looks like I am running into this issue too, which is causing my heavy setup/teardown to be run on each function instead of per session.
Is there any workaround for this?