Remove deprecated scope keyword argument from asyncio marker#1486
Open
mokashang wants to merge 2 commits into
Open
Remove deprecated scope keyword argument from asyncio marker#1486mokashang wants to merge 2 commits into
scope keyword argument from asyncio marker#1486mokashang wants to merge 2 commits into
Conversation
The `scope` keyword argument to `@pytest.mark.asyncio` was deprecated in v0.23 in favor of `loop_scope`. This commit follows through with the deprecation and converts the warning into a usage error for the v2.0 release. Per the discussion on pytest-dev#1475, this goes a step further than just rejecting `scope`: any unrecognized keyword argument to the marker now raises `pytest.UsageError`, and the message identifies the offending kwarg by name (e.g. `'scope'`, `'cope'`) rather than printing a generic "keyword arguments accepted" sentence. The check for positional arguments is split out so the message can mention positionals specifically. The `_loop_scope` fallback to `marker.kwargs.get("scope")` is removed along with the now-unreachable duplicate-loop_scope error path, since `scope` can no longer reach `_parse_asyncio_marker` at all. Fixes pytest-dev#1475
Contributor
|
Thanks for taking this on, @mokashang — the approach matches what @seifertm and I landed on in #1475 (UsageError for any unknown kwarg, dropping the One CI nit: the Run linters job is red on the Splitting the positional-arg error out from the unknown-kwarg path is a nice touch. 👍 |
Author
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1486 +/- ##
==========================================
- Coverage 94.50% 94.48% -0.03%
==========================================
Files 2 2
Lines 510 508 -2
Branches 62 61 -1
==========================================
- Hits 482 480 -2
Misses 22 22
Partials 6 6 ☔ 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.
Fixes #1475.
What changed
The
scopekeyword argument to@pytest.mark.asynciowas deprecated in v0.23 in favor ofloop_scope. Per the v2.0 milestone discussion on #1475, this PR converts the deprecation warning into apytest.UsageError.It takes the broader approach @seifertm suggested in the issue: any unrecognized keyword argument to the marker now raises a usage error, with no special-case handling for
scopeleft in the parser. The error message names the offending kwargs by repr (e.g.'scope','cope') rather than printing a generic "onlyloop_scopeandloop_factoriesare accepted" sentence. Positional-argument validation is split into its own branch so its message can mention positionals specifically rather than lumping them in with unknown kwargs.Surface-level details
_validate_asyncio_markernow raisespytest.UsageError(wasValueError); the kwarg allow-set is{"loop_scope", "loop_factories"}with no"scope"._parse_asyncio_markerloses theif "scope" in kwargs:branch and the duplicate-loop_scope error path (which is now unreachable, sincescopecan no longer reach this function at all).PytestAsyncioFunction._loop_scopedrops theor marker.kwargs.get("scope")fallback._MARKER_SCOPE_KWARG_DEPRECATION_WARNINGand_DUPLICATE_LOOP_SCOPE_DEFINITION_ERRORstrings are deleted.scope=is now an error rather than a warning.Tests
tests/markers/test_function_scope.py::test_warns_when_scope_argument_is_presentremoved; the existingtest_raises_when_scope_and_loop_scope_arguments_are_presentis extended with anfnmatch_linesassertion on the new "unexpected keyword argument 'scope'" message so the regression is pinned to the new error path.tests/markers/test_invalid_arguments.py: the threeValueError-asserting tests are updated to match the newUsageErrormessage wording, and a newtest_error_when_scope_keyword_argument_is_passedcovers the lone-scope=case that was formerly only a deprecation warning.tests/markers/test_function_scope.py+tests/markers/test_invalid_arguments.py, 20 tests) passes locally. The remaining 27 failures inpython -m pytestonmainare pre-existing subprocess-launch failures in my local environment and reproduce verbatim against an unmodifiedmaincheckout, so they're unrelated to this change.Changelog
Added
changelog.d/1475.removed.rstunder theRemovedcategory, since the kwarg is being removed in v2.0.Notes
I deliberately left
_INVALID_LOOP_FACTORIES_KWARGraisingValueErrorrather thanUsageError— that's a value-shape check, not a kwarg-name check, and converting it felt out of scope for this issue. Happy to fold it in if you'd prefer the validators speak the same exception type.