API Reference
pytest-asyncio
A pytest plugin that runs async test functions and fixtures using an asyncio event loop.
Official Documentation ↗CompatibilityThis documentation covers version
v0.23. Check the official docs for the latest API surface.Installation
pip
pip install pytest-asyncioMethods
No methods match this filter.
pytest-asyncio supplies an event loop fixture and marks so async functions are awaited by pytest.
Key Features
- Async test functions and fixtures
- asyncio_mode strict or auto
- Event loop scoping control
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
API reference evidence
Fetched from official sources on 2026-11-08T17:31:00+08:00 via WebFetch https://pytest-asyncio.readthedocs.io/en/latest/concepts.html.
@pytest.mark.asyncio→ signature from https://pytest-asyncio.readthedocs.io/en/latest/concepts.html; official text: “@pytest.mark.asyncio(loop_scope=“module”) async def test_remember_loop():”asyncio_mode→ signature from https://pytest-asyncio.readthedocs.io/en/latest/concepts.html; official text: “[tool.pytest.ini_options] asyncio_mode = “strict””
FAQ
- Do I still need the mark in auto mode?
- No. With asyncio_mode = auto, async tests are discovered automatically and the explicit mark becomes optional.
- How do I share an event loop?
- Use loop_scope on fixtures and marks so fixtures and tests agree on a loop, avoiding cross-loop errors.
- Why does my async fixture fail?
- An async fixture must be declared with pytest_asyncio.fixture rather than the plain pytest fixture decorator.
Report a problem with this API docOpens a pre-filled issue on GitHub.