Skip to content

Deprecate event_loop fixture overrides #311

Closed
@seifertm

Description

@seifertm

There have been multiple feature requests for setting loop exception handlers (#205) and canceling tasks after the event loop has closed (#222, #309). I believe pytest-asyncio is not just about being able to write async tests, but about helping people to write good async code with pytest. That's why I think those requests are warranted.

All feature requests propose to add additional code to the event_loop fixture. However, a fair amount of pytest-asyncio users override the fixture, in order to control its scope. These overrides prevent us from extending the event_loop fixture for existing users. We could ask them to extend their override functions manually, but the fixture definition could become very length (see the code required for task and generator cleanup code in CPython)

I propose to deprecate overrides of the event_loop fixture. This allows the pytest-asyncio developers to modify and extend the event_loop fixture behaviour with special setup code (e.g. loop exception handlers) and teardown code (e.g. task cleanup, raising warnings, etc.).

The additional functionality of the event_loop fixture could be handled in a modular way. Pytest configuration options, for example, can serve as feature flags for new functionality, which would also improve our stability guarantees for new releases.

The fixture scope would be controlled with the asyncio_loop_scope = "session" setting. Other features would add similar settings, e.g. asyncio_exceptions = "raise" to address #205.

Maybe this could be our way towards pytest-asyncio v1.0? I'd be happy to hear your feedback on this idea!

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