Description
Hi,
My project is Python 3.5 only, and it's therefore impossible for me to use async generators in fixtures. But we might be able to workaround this if it were possible to define async finalizers to request
.
E.g.
@pytest.fixture
async def foo_fixture(request):
async def fin():
await some_stuff()
request.addasyncfinalizer(fin)
return 42
Then it would await for each async finalizers before tear down.
Not sure whether it would involve monkey patching on the request object, or what would be acceptable. Maybe there are also more proper solutions that doesn't involve request
or that make use of already existing features? I already tried to use loop.create_task()
in a standard finalizer, unfortunately, the created task seem to execute after teardown which produces the following error message:
2017-06-26 18:15:50,262 - asyncio - ERROR - Task was destroyed but it is pending!
Many thanks!