Skip to content

event loop is closed before my fixture's finalizer runs #30

Closed
@lars-tiede

Description

@lars-tiede

Consider this:

import pytest


async def foo():
    print("foo")


@pytest.yield_fixture
def my_fixture(event_loop):
    print(event_loop.is_closed()) # "False"
    event_loop.run_until_complete(foo()) # "foo"

    yield None

    print(event_loop.is_closed()) # "True"... noooo!
    event_loop.run_until_complete(foo()) # goes boom


@pytest.mark.asyncio
async def test_foo(my_fixture):
    await foo()

Run this code with py.test -s <file> and you'll see the output as indicated by the comments in the code.

The event loop is closed before my finalizer code can run. This is also the case when I write my fixture without a yield, instead adding a finalizer function.

This is weird. I'm pretty sure that this worked just fine a couple of months ago.

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