From 277ae91c2e8d4bf3e7ca70dde6f755ba30a4c255 Mon Sep 17 00:00:00 2001 From: SerageLdin Date: Tue, 24 Nov 2026 13:54:38 +0300 Subject: [PATCH] Validate asyncio_mode in pytest_configure Fixes #1633. Validates asyncio_mode during pytest_configure so invalid values consistently raise a usage error even when quiet mode (-q) suppresses report headers. --- changelog.d/1633.fixed.rst | 1 + pytest_asyncio/plugin.py | 1 + tests/test_simple.py | 11 +++++++++++ 3 files changed, 13 insertions(+) create mode 100644 changelog.d/1633.fixed.rst diff --git a/changelog.d/1633.fixed.rst b/changelog.d/1633.fixed.rst new file mode 100644 index 00000000..2eda9cbd --- /dev/null +++ b/changelog.d/1633.fixed.rst @@ -0,0 +1 @@ +Validate ``asyncio_mode`` in ``pytest_configure`` so invalid values raise a usage error consistently even when no test report header is printed. diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 32b1a834..a15dac0f 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -281,6 +281,7 @@ def _validate_scope(scope: str | None, option_name: str) -> None: def pytest_configure(config: Config) -> None: + _get_asyncio_mode(config) default_fixture_loop_scope = config.getini("asyncio_default_fixture_loop_scope") if default_fixture_loop_scope != _MATCH_FIXTURE_SCOPE: _validate_scope( diff --git a/tests/test_simple.py b/tests/test_simple.py index 8ddeade3..adb0557f 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -99,3 +99,14 @@ def test_invalid_asyncio_mode(pytester): result.stderr.fnmatch_lines( "ERROR: 'True' is not a valid asyncio_mode. Valid modes: auto, strict." ) + + +def test_invalid_asyncio_mode_quiet_mode(pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") + pytester.makepyfile("def test_sync(): pass") + result = pytester.runpytest("-q", "-o", "asyncio_mode=bogus") + result.stderr.no_fnmatch_line("INTERNALERROR> *") + result.stderr.fnmatch_lines( + "ERROR: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict." + ) + assert result.ret == pytest.ExitCode.USAGE_ERROR