Skip to content

Use issue_config_time_warning for the unset-loop-scope deprecation - #1557

Open
mathewOracle wants to merge 2 commits into
pytest-dev:mainfrom
mathewOracle:fix/1142-config-time-warning-not-captured
Open

Use issue_config_time_warning for the unset-loop-scope deprecation#1557
mathewOracle wants to merge 2 commits into
pytest-dev:mainfrom
mathewOracle:fix/1142-config-time-warning-not-captured

Conversation

@mathewOracle

Copy link
Copy Markdown

pytest_configure warns via a plain warnings.warn() when asyncio_default_fixture_loop_scope is unset. Per pytest's own docs on Config.issue_config_time_warning, warnings raised this way during pytest_configure can't be captured the way per-test warnings are -- pytest has no way to install a hookwrapper around pytest_configure -- so the warning is silently dropped: it never reaches the warnings summary, and doesn't respect -W/filterwarnings.

$ pytest  # asyncio_default_fixture_loop_scope left unset
2 passed in 0.01s   # no warning shown anywhere, including with -W default

Depending on the caller's global warning filter state it can also raise an uncaught PytestDeprecationWarning straight out of pytest_configure, crashing the run outright (reproducible via pytester's in-process runpytest(), which shares the outer process's filters).

Config.issue_config_time_warning is pytest's documented mechanism for exactly this case, and is what pytest's own core plugins use for their config-time deprecations (e.g. _pytest/pastebin.py). Switching to it makes the warning show up in the warnings summary and respect the caller's filters, with no change to the message or when it fires.

Verified live against the exact repro from the issue: the warning now appears in a plain pytest run with no flags needed. Added a regression test that fails against the previous code (either silently, or via INTERNALERROR depending on inherited filters) and passes with this change, plus a sanity test that no warning fires when the option is configured. Full test suite shows identical pre-existing failures/errors before and after this change (unrelated compatibility gaps with the installed pytest version); no new failures introduced. ruff check clean.

Closes #1142

`pytest_configure` warns via a plain `warnings.warn()` when
`asyncio_default_fixture_loop_scope` is unset. Per pytest's own docs on
`Config.issue_config_time_warning`, warnings raised this way during
`pytest_configure` can't be captured the way per-test warnings are --
pytest has no way to install a hookwrapper around `pytest_configure` --
so the warning is silently dropped: it never reaches the warnings
summary, and doesn't respect `-W`/`filterwarnings`.

    $ pytest  # asyncio_default_fixture_loop_scope left unset
    2 passed in 0.01s   # no warning shown anywhere, including with -W default

Depending on the caller's global warning filter state it can also raise
an uncaught PytestDeprecationWarning straight out of pytest_configure,
crashing the run outright (reproducible via pytester's in-process
runpytest(), which shares the outer process's filters).

`Config.issue_config_time_warning` is pytest's documented mechanism for
exactly this case, and is what pytest's own core plugins use for their
config-time deprecations (e.g. _pytest/pastebin.py). Switching to it
makes the warning show up in the warnings summary and respect the
caller's filters, with no change to the message or when it fires.

Verified live against the exact repro from the issue: the warning now
appears in a plain `pytest` run with no flags needed. Added a
regression test that fails against the previous code (either silently,
or via INTERNALERROR depending on inherited filters) and passes with
this change, plus a sanity test that no warning fires when the option
is configured. Full test suite shows identical pre-existing
failures/errors before and after this change (unrelated compatibility
gaps with the installed pytest version); no new failures introduced.
ruff check clean.

Closes pytest-dev#1142
@codecov-commenter

codecov-commenter commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (dcd61c2) to head (fe20426).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1557      +/-   ##
==========================================
+ Coverage   94.50%   95.29%   +0.78%     
==========================================
  Files           2        2              
  Lines         510      510              
  Branches       62       62              
==========================================
+ Hits          482      486       +4     
+ Misses         22       20       -2     
+ Partials        6        4       -2     

☔ 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.

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.

Missing warning about unconfigured asyncio_default_fixture_loop_scope

2 participants