Open
Description
Consider this test case:
import pytest
CALL_COUNT = 0
@pytest.fixture(scope="module")
def fixture(_dynamic_param):
global CALL_COUNT
CALL_COUNT += 1
def pytest_generate_tests(metafunc):
if "_dynamic_param" in metafunc.fixturenames:
metafunc.parametrize("_dynamic_param", ["foo"], scope="module")
@pytest.mark.parametrize("param", ["bar", "zaz"])
def test_1(fixture, param):
global CALL_COUNT
assert CALL_COUNT == 1
The output is:
% py.test test_bug.py
platform linux2 -- Python 2.7.9 -- py-1.4.30 -- pytest-2.7.2
rootdir: /tmp, inifile:
collected 2 items
test_bug.py .F
== FAILURES ==
__ test_1[foo-zaz] __
fixture = None, param = 'zaz'
@pytest.mark.parametrize("param", ["bar", "zaz"])
def test_1(fixture, param):
global CALL_COUNT
> assert CALL_COUNT == 1
E assert 2 == 1
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
.
Maybe related to #635
Thanks