Use issue_config_time_warning for the unset-loop-scope deprecation - #1557
Open
mathewOracle wants to merge 2 commits into
Open
Use issue_config_time_warning for the unset-loop-scope deprecation#1557mathewOracle wants to merge 2 commits into
mathewOracle wants to merge 2 commits into
Conversation
`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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pytest_configurewarns via a plainwarnings.warn()whenasyncio_default_fixture_loop_scopeis unset. Per pytest's own docs onConfig.issue_config_time_warning, warnings raised this way duringpytest_configurecan't be captured the way per-test warnings are -- pytest has no way to install a hookwrapper aroundpytest_configure-- so the warning is silently dropped: it never reaches the warnings summary, and doesn't respect-W/filterwarnings.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_warningis 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
pytestrun 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