pytest-dev / pytest-dev/pytest-asyncio
Don't warn about `asyncio_default_fixture_loop_scope` unless the test suite uses `pytest-asyncio`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 207
- Avg merge
- 5h 35m
- Merged PRs (30d)
- 9
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with pytest_asyncio/plugin.py at the pytest_configure warning reported near line 247, then reproduce the behavior using test_a.py and pytester.runpytest_inprocess. Run the listed pytest commands with pytest-asyncio installed; done means the no-async-test suite succeeds under -Werror without removing or relaxing the deprecation warning when pytest-asyncio is actually used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100