Open
Description
There seems to be a problem with our reordering code that optimizes higher-level fixtures' execution order.
import pytest
@pytest.fixture(scope="session")
def prepare(request):
print("\nprepare setup with {!r}".format(request.param))
@pytest.mark.parametrize('prepare', ["dina"], indirect=True, scope="session")
def test_1(prepare):
print("Test1 done\n")
@pytest.mark.parametrize('prepare', ["mor"], indirect=True, scope="session")
def test_2(prepare):
print("Test2 done\n")
@pytest.mark.parametrize('prepare', ["dina"], indirect=True, scope="session")
def test_3(prepare):
print("Test3 done\n")
I get this output:
λ pytest .tmp\test_fix_session.py -sq
prepare setup with 'dina'
Test1 done
.
prepare setup with 'mor'
Test2 done
.
prepare setup with 'dina'
Test3 done
.
3 passed in 0.02s
We would expect it to reorder the tests to [test_1, test_3, test_2]
so the fixture would execute only twice, instead of 3 times as it is doing now, so definitely looks like a bug (unless I'm missing something).
Thanks @dina809 for the original report (#8328).
Originally posted by @nicoddemus in #8328 (comment)