I have a test in a class with parametrized indirect class
scoped fixture. When another regular class
scoped fixture is calling the parametrized fixture, its execution seems to be more function
scoped. Meaning the regular fixture is called again, for every test method. When removing the parametrized fixture call, it is executed once per class as expected.
I am aware of fixture life cycle as explained here, but I am not exiting the class. What I am missing here?
pytest-7.0.1, pytest-asyncio-0.17.2
Code:
@pytest_asyncio.fixture(scope='class')
async def some_fixture(request, iteration): # <---- when not using 'iteration', works as expected
print(f'-some_fixture-{request.scope}-start')
yield
print(f'-some_fixture-{request.scope}-end')
@pytest_asyncio.fixture(scope='class')
async def iteration(self, request):
print(f'-iteration-{request.scope}-start')
yield request.param
print(f'-iteration-{request.scope}-end')
@pytest.mark.parametrize('iteration', range(1, ITERATIONS + 1), indirect=True) # <---- tried adding scope='class', no success
@pytest.mark.asyncio
class Something:
async def test_something(self, iteration, some_fixture):
print(test_body)
Output:
test_foo.py::test_something[1] -iteration-class-start
-some_fixture-class-start
-test_body
PASSED
test_foo.py::test_something[2] -some_fixture-class-end # <---- why it end here?
-iteration-class-end
-iteration-class-start
-some_fixture-class-start # <--- called twice
-test_body
PASSED
-some_fixture-class-end
-iteration-class-end