Repository navigation
fix: validate asyncio_mode in pytest_configure - #1639
Open
saruk-vedant wants to merge 2 commits into
Open
saruk-vedant wants to merge 2 commits into
saruk-vedant wants to merge 2 commits into
Conversation
Call _get_asyncio_mode in pytest_configure so an invalid asyncio_mode raises a usage error at configuration time, even when -q suppresses the report header where the mode was previously first read. Fixes pytest-dev#1633
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1639 +/- ##
==========================================
+ Coverage 94.86% 94.87% +0.01%
==========================================
Files 2 2
Lines 506 507 +1
Branches 60 60
==========================================
+ Hits 480 481 +1
Misses 21 21
Partials 5 5 ☔ 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.
Summary
asyncio_modewas only validated by_get_asyncio_mode(), which first runs frompytest_report_header. With-qthe header is suppressed, so an invalid value was silently accepted when no async test was collected (a plain1 passedrun), and only surfaced later as a per-test error when an async test was present.This PR calls
_get_asyncio_mode(config)inpytest_configure, so an invalidasyncio_modenow raises the same single usage error (exit code 4) in all cases, matching howasyncio_default_fixture_loop_scopeis already validated there.Also adds a changelog fragment (
changelog.d/1633.fixed.rst).How to test
pytest -o asyncio_mode=bogus(non-quiet): exit 4,ERROR: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict.pytest -q -o asyncio_mode=bogus test_sync.py(sync-only tests): previously1 passed, now exit 4 with the same error.pytest -q -o asyncio_mode=bogus test_async.py: previously a per-test setup error, now exit 4 with the same single error.pytest -q --asyncio-mode=bogusand a bogus value in the ini file: exit 4 with the same error.auto,strict) and the default (no setting) still pass in quiet and non-quiet runs.asyncio_default_fixture_loop_scopestill raises its own usage error when the mode is valid.Verification
tests/test_simple.py:test_invalid_asyncio_mode_quiet(parametrized over the-oini override and the--asyncio-modeoption) andtest_invalid_asyncio_mode_quiet_with_async_test.pytest tests/test_simple.py tests/modes/ -q: 22 passed, 3 skipped.pytest tests/ -q: 263 passed, 3 skipped, 1 failed. The single failure (tests/test_set_event_loop.py::test_asyncio_run_after_async_fixture_does_not_leak_loop) is pre-existing: it fails identically on the unmodified tree (aPytestAssertRewriteWarningraised as an error in the inner pytester run, unrelated to this change).ruff check(repo-pinned 0.14.13) on the changed files: all checks passed.ruff formaton the changed files flags only pre-existing hunks.pyright pytest_asyncio/ tests/: 0 errors.Fixes #1633