I would expect that session fixtures are run once per session - but it seems if a flaky test reruns, it will run session scoped fixtures' teardown code, and then their setup again.
This can result in costly setup/teardown being unnecessarily rerun, and also seems to go against the whole point of labelling the fixture session
Reproduction:
@pytest.fixture(scope="session")
def example_fixture():
print("\nSetup")
yield
print("Teardown")
@pytest.mark.flaky(reruns=1)
def test_example_fixture(example_fixture):
assert 0
Running with pytest -s -v ... I get:
plugins: timeout-1.2.0, rerunfailures-2.2, repeat-0.4.1, ordering-0.5
collected 1 items
scripts/autotest/tests/conftest.py::test_example_fixture
Setup
Teardown
RERUN
scripts/autotest/tests/conftest.py::test_example_fixture
Setup
Teardown
FAILED
I would expect that session fixtures are run once per session - but it seems if a
flakytest reruns, it will run session scoped fixtures' teardown code, and then their setup again.This can result in costly setup/teardown being unnecessarily rerun, and also seems to go against the whole point of labelling the fixture
sessionReproduction:
Running with
pytest -s -v ...I get: