The following pytest fixture
@pytest.fixture(scope="module")
def gen_factory():
def _gen_factory(owner: str):
value = ...
yield value
print('gen teardown')
yield _gen_factory
yields a factory used multiple times.
In a test case, I use that fixture to create two factory and use them to produce some values:
@pytest.mark.asyncio
def test_case(gen_factory):
gen1 = gen_factory('owner1')
gen2 = gen_factory('owner2')
val1 = next(gen1)
val2 = next(gen2)
...
next(gen1)
next(gen2)
What happens is that the print('gen teardown') is called only once and then the loop is closed and the second next() call raises a StopIteration error.
What am I missing here? Why is the second print not happening?