Skip to content

1.1.0: Session fixture with asyncio_default_fixture_loop_scope=function yields You tried to access the function scoped fixture _function_scoped_runner with a session scoped request object #1175

@mgorny

Description

@mgorny

Hit this in the wild while trying to run fakeredis's test suite.

Trivial reproducer:

import pytest_asyncio


@pytest_asyncio.fixture(scope="session")
def foo():
    pass


def test_foo(foo):
    pass
$ pytest -o asyncio_default_fixture_loop_scope=function test_foo.py -vv
========================================================= test session starts =========================================================
platform linux -- Python 3.13.5, pytest-8.4.1, pluggy-1.6.0 -- /tmp/fakeredis-py/.venv/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default'
rootdir: /tmp
plugins: asyncio-1.1.0, hypothesis-6.136.6
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 1 item                                                                                                                      

test_foo.py::test_foo ERROR                                                                                                     [100%]

=============================================================== ERRORS ================================================================
_____________________________________________________ ERROR at setup of test_foo ______________________________________________________
ScopeMismatch: You tried to access the function scoped fixture _function_scoped_runner with a session scoped request object. Requesting fixture stack:
test_foo.py:4:  def foo()
Requested fixture:
pytest-asyncio/pytest_asyncio/plugin.py:774:  def _scoped_runner(event_loop_policy, request: 'FixtureRequest') -> 'Iterator[Runner]'
======================================================= short test summary info =======================================================
ERROR test_foo.py::test_foo - Failed: ScopeMismatch: You tried to access the function scoped fixture _function_scoped_runner with a session scoped request object. Requesting fixture stack:
test_foo.py:4:  def foo()
Requested fixture:
pytest-asyncio/pytest_asyncio/plugin.py:774:  def _scoped_runner(event_loop_policy, request: 'FixtureRequest') -> 'Iterator[Runner]'
========================================================== 1 error in 0.12s ===========================================================

Reproduced on 92962d1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions