Skip to content

Add async finalizers to the request-context #59

Closed
@gilbsgilbs

Description

@gilbsgilbs

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions