Skip to content

Warn when a fixture for a different loop_scope is requested #1514

Description

@seifertm

Pytest-asyncio currently allows requesting fixtures that have a different loop_scope than the requesting test or fixture. Since fixtures with different loop scopes use different asyncio event loops, this can lead to unexpected errors., e.g. trying to access a task that was created on a different loop.

This can happen when:

  • a test requests a fixture, but the loop_scopes don't match
  • a fixture requests another fixture, but the loop_scopes don't match

Mixing fixtures with different loop scopes is almost certainly a user error and should result in a warning.

Work on this issue was done during the pytest sprint 2026, sponsored by Omicron.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions