Skip to content

Support for "yield" fixtures #16

@njsmith

Description

@njsmith

Pytest allows fixtures to contain a yield, and do both setup and teardown:

@pytest.fixture
def http_server():
    server = start_server()
    yield
    server.stop()

We should support this for async fixtures.

It looks like the way Pytest does this is that when it calls a fixture function (in _pytest.fixtures.call_fixture_func), and it detects that the function is a generator, then it calls request.addfinalizer to make sure the cleanup happens.

I don't think this works for us... I guess what we would need to do is to do a second pass over the the fixture tree to call some AsyncFixture.cleanup method, and then implement that for fixtures that are async generators?

Ugh, Pytest is so confusing and complicated.

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