Skip to content

Invalid asyncio_mode is only validated when the report header is printed #1633

Backlog

Description

@RonnyPfannschmidt

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest-asyncio maintainers; I prompted it, it did the work, I read it.

asyncio_mode is checked by _get_asyncio_mode(), which runs first from pytest_report_header. With -q there is no header, so a bad value is not reported at configuration time:

$ pytest -o asyncio_mode=bogus                 # header printed
ERROR: 'bogus' is not a valid asyncio_mode. Valid modes: auto, strict.

$ pytest -q -o asyncio_mode=bogus test_sync.py   # only sync tests
1 passed                                          # silently accepted

$ pytest -q -o asyncio_mode=bogus test_async.py  # async test present
ERROR test_async.py - pytest.UsageError: 'bogus' is not a valid asyncio_mode...
Interrupted: 1 error during collection            # traceback, exit 2

asyncio_default_fixture_loop_scope is already validated in pytest_configure. Calling _get_asyncio_mode(config) there too would give the same single usage error (exit 4) in all three cases.

Seen on main (599fb32). Spotted while reviewing #1632, which proposes that change but comes from an account that has been banned from pytest-dev.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions