Repository navigation
Validate asyncio_mode at configuration time, not only in the report header - #1632
qianeric-backup wants to merge 1 commit into
Conversation
…eader
`_get_asyncio_mode()` is called from `pytest_report_header()`, so the value is
only checked when the header is printed. With `-q` the header is skipped and a
typo in the option is not a configuration error any more - it is raised while
setting up each test, so the run shows an internal traceback and a per-test
ERROR instead of one message:
$ pytest -q -o asyncio_mode=bogus
...
==================================== ERRORS ====================================
___________________________ ERROR at setup of test_a ___________________________
def _get_asyncio_mode(config: Config) -> Mode:
try:
> return Mode(val)
E pytest.UsageError: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict.
The sibling options are validated in `pytest_configure()` and fail before
collection:
$ pytest -q -o asyncio_default_fixture_loop_scope=bogus ; echo $?
ERROR: 'bogus' is not a valid asyncio_default_fixture_loop_scope. Valid scopes are: ...
4
## Change
`pytest_configure()` validates the mode with the same helper the report header
uses:
$ pytest -q -o asyncio_mode=bogus ; echo $?
ERROR: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict.
4
| case | before | after |
|---|---|---|
| `-o asyncio_mode=bogus` (header printed) | `ERROR: ...`, exit 4 | unchanged |
| `-q -o asyncio_mode=bogus` | per-test `ERROR at setup` with a traceback, exit 1 | `ERROR: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict.`, exit 4 |
| `-o asyncio_mode=auto` / `strict` | works | unchanged |
## Tests
`test_invalid_asyncio_mode_is_a_config_error` parametrizes the existing
`test_invalid_asyncio_mode` with and without `-q` and asserts the exit code is
`USAGE_ERROR`. `pytest tests/test_simple.py tests/modes tests/markers`: 70
passed, 3 skipped with the change; on the current tree the `-q` case fails
because the error is raised per test instead.
I did not add a `changelog.d` entry - tell me the fragment number you want and I
will add it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1632 +/- ##
==========================================
+ 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:
|
|
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest-asyncio maintainers; I prompted it, it did the work, I read it. This PR comes from an unattended agent loop. The account has opened 93 PRs across unrelated projects since July, 30 of them on 2026-11-22 alone at 10-15 minute intervals, with no issue or discussion before any of them. Four landed in pytest-dev within a day. The sibling pytest-dev/pytest-xdist#1433 would have broken a documented configuration, because the agent misread the very docs it cited as evidence. The one-line change here is fine on its own: with The account is being banned from pytest-dev. Our AI policy: https://github.com/pytest-dev/pytest/blob/main/CONTRIBUTING.rst Generated by Claude Code |
_get_asyncio_mode()is called frompytest_report_header(), so the value is only checked when the header is printed. With-qthe header is skipped and a typo in the option is not a configuration error any more — it is raised while setting up each test, so the run shows a traceback and a per-test ERROR instead of one message:The sibling options are validated in
pytest_configure()and fail before collection:Change
pytest_configure()validates the mode with the same helper the report header uses:-o asyncio_mode=bogus(header printed)ERROR: ..., exit 4-q -o asyncio_mode=bogusERROR at setupwith a traceback, exit 1ERROR: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict., exit 4-o asyncio_mode=auto/strictasyncio_modeset)Mode.STRICTTests
test_invalid_asyncio_mode_is_a_config_errorparametrizes the existingtest_invalid_asyncio_modewith and without-qand asserts the exit code isUSAGE_ERROR.pytest tests/test_simple.py tests/modes tests/markers: 70 passed, 3 skipped with the change; on the current tree the-qcase fails because the error is raised per test instead.I did not add a
changelog.dentry — tell me the fragment number you want and I will add it.