Skip to content

Don't warn about asyncio_default_fixture_loop_scope unless the test suite uses pytest-asyncio #1344

@Liam-DeVoe

Description

@Liam-DeVoe

Hi all. I am not a user of pytest-asyncio, but it has gotten installed to my environment through one transitive dependency or another.

My test suite has no async tests and runs under -Werror. One of my tests uses pytester.runpytest_inprocess, which fails iff pytest-asyncio is installed due to the deprecation warning:

INTERNALERROR>   File "/Users/tybug/.local/share/uv/python/cpython-3.13.11-macos-aarch64-none/lib/python3.13/site-packages/pytest_asyncio/plugin.py", line 247, in pytest_configure
INTERNALERROR>     warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
INTERNALERROR>     ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> pytest.PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
INTERNALERROR> The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"
================================================================= short test summary info ==================================================================
FAILED test_a.py::test_a - assert <ExitCode.INTERNAL_ERROR: 3> == 0
==================================================================== 1 failed in 0.06s =====================================================================
 ~/Desktop/pytest_inprocess_repro λ 

Reproduction steps:

mkdir pytest_asyncio_repro && cd pytest_asyncio_repro
uv venv .venv --python 3.12
uv pip install --python .venv/bin/python pytest pytest-asyncio
# test_a.py
pytest_plugins = ["pytester"]

def test_a(pytester):
    pytester.makepyfile(test_inner="""
def test_b(): pass
""")
    result = pytester.runpytest_inprocess()
    assert result.ret == 0
  • .venv/bin/python -m pytest test_a.py: passes
  • .venv/bin/python -m pytest test_a.py -Werror: fails

I'm not asking for the deprecation warning to be removed or relaxed. But it would be really great if having pytest-asyncio installed in my environment didn't cause my tests to fail!

I also don't know why this requires pytester.runpytest_inprocess to trigger. I would expect this to be a problem when running pytest at the top level as well. This may be why nobody has complained about this yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions