Open palocziarpad opened 2 years ago
I had the same issue. But I doubt it should be considered a Pytest bug.
The commit 80d4dd6f0b... changed the old way of comparing cache keys' values with ==
in favor of identity comparison.
During the collection stage pytest_generate_tests
is called for each function TestA.test_a
, TestB.test_b
, etc, and each time a new metafunc
is generated. It means that metafunc.parametrize
is called more than once for alarms
where the elements' addresses/identities are not the same between invocations (as they're produced with split
). Note that metafunc.config.getoption("--indirect-params")
is always the same object.
As a quick solution, you can get rid of split
and use --indirect-params
just to accumulate values:
def pytest_addoption(parser):
parser.addoption("--indirect-params", action="append")
def pytest_generate_tests(metafunc):
if 'indirect_param' in metafunc.fixturenames:
alarms = metafunc.config.getoption("--indirect-params")
metafunc.parametrize("indirect_param", alarms, indirect=True)
Pytest - 5.4.0
conftest.py
test_a.py
Incorrect behavior
Expectation is that the "class fixture start with param ABC" written out only once.
Without the indirect parametization: The indirect parametization version should work in a similar way.