pytest-aio

raw JSON →
2.1.7 verified Fri May 01 auth: no python

Pytest plugin for testing async Python code. Provides fixtures and markers for running async tests with pytest. Supports asyncio, trio, and other async frameworks. Current version 2.1.7, released under Apache 2.0 license. Active development, weekly commits.

pip install pytest-aio
error ImportError: cannot import name 'asyncio' from 'pytest_aio'
cause Trying to import asyncio from pytest_aio incorrectly.
fix
Use 'import asyncio' directly (stdlib), not from pytest_aio.
error TypeError: async def test() got an unexpected keyword argument 'loop'
cause Old code passing loop fixture to async test.
fix
Remove 'loop' argument; pytest-aio 2.x handles event loop automatically.
error ModuleNotFoundError: No module named 'pytest_aio'
cause pytest-aio not installed or not in virtual environment.
fix
Run 'pip install pytest-aio' in your environment.
gotcha pytest-aio does not automatically detect async fixtures. Use @pytest.fixture with asyncio marker or use async def fixture (requires pytest-aio>=2.0).
fix Upgrade to 2.x or mark async fixtures explicitly.
deprecated The @pytest.mark.asyncio marker is deprecated in pytest-aio 2.x; use 'async def' directly without marker.
fix Remove marker and simply write 'async def test_async():'
breaking Breaking change in 2.0: Removed support for Python <3.10. async fixtures now require pytest-aio 2.x.
fix Ensure Python >=3.10 and update tests to remove markers.

Basic async test using pytest-aio. Mark test with @pytest.mark.asyncio.

# test_async.py
import pytest

@pytest.mark.asyncio
async def test_async_example():
    result = await some_async_function()
    assert result == expected_value