Skip to content

fix: only warn about asyncio_default_fixture_loop_scope when needed#1507

Closed
pctablet505 wants to merge 4 commits into
pytest-dev:mainfrom
pctablet505:fix-pytest-asyncio-1344-conditional-warning
Closed

fix: only warn about asyncio_default_fixture_loop_scope when needed#1507
pctablet505 wants to merge 4 commits into
pytest-dev:mainfrom
pctablet505:fix-pytest-asyncio-1344-conditional-warning

Conversation

@pctablet505

@pctablet505 pctablet505 commented Jul 15, 2026

Copy link
Copy Markdown

Fixes #1344

When pytest-asyncio is installed as a transitive dependency, the plugin currently emits its PytestDeprecationWarning about an unset asyncio_default_fixture_loop_scope unconditionally from pytest_configure. That means any test suite running under -Werror will hit an internal error as soon as pytest-asyncio is present, even if the suite has no async tests or fixtures. The reporter saw this with pytester.runpytest_inprocess, but the underlying issue is that the warning fires the moment the plugin loads.

As noted in the issue thread, this happens because pytest enables all installed plugins by default. The suggested workaround of passing -p no:asyncio works, but it is not reasonable to expect users who never chose to install pytest-asyncio to discover and apply it.

This change moves the warning into pytest_fixture_setup, so it is only emitted when an async fixture is actually being set up and neither the global asyncio_default_fixture_loop_scope nor a per-fixture loop_scope has been configured. A StashKey on the Config object keeps track of whether the warning has already been emitted, preventing it from repeating for every async fixture.

I added regression tests for both sides of the behavior: a plain synchronous test now passes under -Werror without triggering the warning, while a suite that does use an async fixture still sees the deprecation warning as expected.

@codecov-commenter

codecov-commenter commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.81%. Comparing base (1975f90) to head (95da65a).

Files with missing lines Patch % Lines
pytest_asyncio/plugin.py 40.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1507      +/-   ##
==========================================
- Coverage   94.50%   93.81%   -0.70%     
==========================================
  Files           2        2              
  Lines         510      517       +7     
  Branches       62       63       +1     
==========================================
+ Hits          482      485       +3     
- Misses         22       26       +4     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pctablet505

Copy link
Copy Markdown
Author

Closing this after taking another look at the wider discussion. The comment on #1344 already leaned toward finishing the deprecation rather than making the warning conditional, and that work is underway in #1444 (default the fixture loop scope to function and drop the warning entirely, per #924, targeted at v1.4.0). Once that lands this warning path goes away, so a conditional-suppression workaround here isn't worth review time.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants