Open marshall7m opened 2 years ago
I'm running into the same issue. Pytest does not teardown parent fixtures to a parametrized fixture in class scope until all test class instances have run.
You can work around the bug by making the dependency fixture depend on the parametrized fixture. In the example by @marshall7m , you would add the parameter scenario
to conf_fixt
:
conftest.py
import pytest
from random import randint
@pytest.fixture(scope='class')
def conf_fixt(scenario):
y = randint(1, 100000)
yield y
print(f'teardown: {y}')
Now when you run pytest --setup-plan
it results in
issue9427/test_foo.py
SETUP C scenario['scenario_1']
SETUP C conf_fixt (fixtures used: scenario)
issue9427/test_foo.py::TestZoo::test_scenario[scenario_1] (fixtures used: conf_fixt, request, scenario)
issue9427/test_foo.py::TestZoo::test_other[scenario_1] (fixtures used: conf_fixt, request, scenario)
TEARDOWN C conf_fixt
TEARDOWN C scenario['scenario_1']
SETUP C scenario['scenario_2']
SETUP C conf_fixt (fixtures used: scenario)
issue9427/test_foo.py::TestZoo::test_scenario[scenario_2] (fixtures used: conf_fixt, request, scenario)
issue9427/test_foo.py::TestZoo::test_other[scenario_2] (fixtures used: conf_fixt, request, scenario)
TEARDOWN C conf_fixt
TEARDOWN C scenario['scenario_2']
It's awkward though and not possible if your parametrized fixture has a direct dependency.
I'm running pytest 6.2.5
& python 3.8.10
Problem:
The
conftest.py
fixture's setup/teardown is not executed after each test class iteration.When running
pytest test_foo.py --setup-plan
, theSETUP C conf_fixt
is only executed before the first parametrized class iteration, andTEARDOWN C conf_fixt
is only executed after the last parameterized class iteration is complete.Related Files:
conftest.py
test_foo.py
Actual:
pytest test_foo.py
pytest test_foo.py --setup-plan
Expected:
pytest test_foo.py
pytest test_foo.py --setup-plan
Attempts:
Add the
conf_fixt
fixture to thepytest.marks.parametrize()
decorator like so:Same Actual and Expected output as the original problem.