Repository navigation
Validate asyncio marker loop_scope via _validate_scope - #1585
Open
JingHao-Leon wants to merge 1 commit into
Open
JingHao-Leon wants to merge 1 commit into
JingHao-Leon wants to merge 1 commit into
Conversation
The marker's loop_scope was checked with a bare assert, so an invalid value
surfaced as AssertionError: assert 'x' in {'class', 'function', ...}. Use the
helper that already validates the two ini options instead, so the reported
message names the argument and lists the valid scopes.
JingHao-Leon
force-pushed
the
fix-marker-loop-scope-validation
branch
from
October 19, 2026 10:33
568df45 to
9aa2fa5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1585 +/- ##
==========================================
+ Coverage 94.50% 94.89% +0.38%
==========================================
Files 2 2
Lines 510 509 -1
Branches 62 61 -1
==========================================
+ Hits 482 483 +1
+ Misses 22 21 -1
+ Partials 6 5 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Description
An invalid
loop_scopeon theasynciomarker is validated with a bareassert, so a typois reported as a Python
AssertionErrorprinting a set repr:The same mistake in
asyncio_default_test_loop_scopealready readsERROR: "bogus" is not a valid asyncio_default_test_loop_scope. Valid scopes are: function, class, module, package, session.Both settings accept the same five scopes, and the plugin already has a helper that produces the
second message — the marker path just doesn't call it. The reported error also doesn't say which
argument was wrong.
This changes the reported message only; it does not change which inputs are accepted or rejected.
Root cause
pytest_asyncio/plugin.py:982-983, in_parse_asyncio_marker:This is the only validation of the marker's
loop_scope/scope.pytest_configurevalidatesthe two ini options through
_validate_scope(pytest_asyncio/plugin.py:285), which raisespytest.UsageErrorwith the message above and returns early forNone. Replacing theassertwith that call makes both paths use the same validation:
Validation
tests/test_fixture_loop_scopes.py::test_invalid_marker_loop_scope_raises_error, added next tothe existing
test_invalid_default_fixture_loop_scope_raises_error, which covers the ini-optionhalf of the same contract.
Clean
mainbaseline for comparison is295 passed, 3 skipped; the one added test accounts forthe difference. No existing test changed behaviour.
Python 3.13.9, pytest 9.1.1.
PYTHONPATH=$PWDis set because this machine also haspytest-asyncio installed in site-packages;
python -c "import pytest_asyncio; print(pytest_asyncio.__file__)"resolves to the checkout under that path.
Fixes #1584
This change was prepared with the assistance of an AI coding agent.