Use issue_config_time_warning for the unset-loop-scope deprecation - #1557
mathewOracle wants to merge 3 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:
|
| _validate_scope(default_fixture_loop_scope, "asyncio_default_fixture_loop_scope") | ||
| if not default_fixture_loop_scope: | ||
| warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET)) | ||
| # A plain warnings.warn() here is silently lost: pytest can't wrap |
There was a problem hiding this comment.
I think we can delete this comment. It reads more like developer commentary pertaining to this PR rather than anything useful long-term.
There was a problem hiding this comment.
Can we simplify these changes? Some of the assertions pass on main and, as-written, obfuscates the behaviour we're trying to protect. I'd also expect a test that covers suppressing this warning through -W and filterwarnings.
There was a problem hiding this comment.
Can we make this fragment more precise (a user could mistakenly interpret this as thinking we haven't been emitting this warning at all) and remove the implementation detail about Config.issue_config_time_warning?
- Drop the PR-commentary comment in pytest_configure. - Replace the broad loop-scope tests with focused ones: the warning shows up in the summary, and is silenceable via -W and filterwarnings. - Reword the changelog fragment to describe user-visible behaviour rather than the Config.issue_config_time_warning implementation detail.
|
Thanks for the review @tjkuson! Pushed 6014a08 addressing all three points:
Note: |
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