Install & Compatibility
Where this runs
tested against v? · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.450s · 82.9MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.9s · import 0.393s · 154MB
119MB installed
● package 119MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pytest.mark.anyio
✓ import pytest
# ... then use @pytest.mark.anyio on async test functions or pytestmark = pytest.mark.anyio
✗ from pytest_anyio import anyio_backend
The plugin is integrated into 'anyio'; access markers and fixtures via 'pytest' directly after installing 'anyio'.
anyio_backend (fixture)
✓ def test_my_async_function(anyio_backend): ...
The 'anyio_backend' fixture is automatically provided by the 'anyio' pytest plugin when 'anyio' is installed.
To write asynchronous tests with AnyIO and pytest, ensure `anyio` and `pytest` are installed. You can mark individual asynchronous test functions with `@pytest.mark.anyio`, apply `pytestmark = pytest.mark.anyio` at the module level to mark all tests, or configure `anyio_mode = 'auto'` in your `pytest.ini`. The `anyio_backend` fixture is automatically available for managing async backends. Asynchronous fixtures are also fully supported by marking them with `@pytest.fixture` and `@pytest.mark.anyio`.
import pytest
import anyio
# Option 1: Mark individual async test functions
@pytest.mark.anyio
async def test_async_function():
await anyio.sleep(0.001)
assert True
# Option 2: Mark all async test functions in a module
pytestmark = pytest.mark.anyio
async def test_another_async_function_module_wide():
await anyio.sleep(0.001)
assert True
# Option 3: Use the anyio_backend fixture (often implicitly, or for custom backend control)
async def test_with_anyio_backend_fixture(anyio_backend):
# 'anyio_backend' can be used to explicitly specify a backend or is implicitly available
# For example, to run only on 'asyncio':
# @pytest.mark.parametrize('anyio_backend', ['asyncio'])
# async def test_on_asyncio_only(anyio_backend):
await anyio.sleep(0.001)
assert True
# Example of an asynchronous fixture
@pytest.fixture
@pytest.mark.anyio
async def async_data():
# Simulate async setup
await anyio.sleep(0.001)
yield {'key': 'value'}
# Simulate async teardown
await anyio.sleep(0.001)
async def test_using_async_fixture(async_data):
assert async_data['key'] == 'value'
Debug
Known issues
breakingThe `pytest-anyio` package is deprecated and should NOT be installed. Its functionality was absorbed into the `anyio` library itself.fixUninstall `pytest-anyio` if present (`pip uninstall pytest-anyio`) and ensure you have `anyio` (>=3.0.0) and `pytest` installed (`pip install anyio pytest`).
affects: All versions (from 0.0.0 onwards)
gotchaAsynchronous test functions and fixtures are not automatically detected by pytest without proper marking or configuration. They require explicit indications for the AnyIO plugin to run them correctly.fixUse `@pytest.mark.anyio` on async test functions/fixtures, or add `anyio_mode = "auto"` to your `pytest.ini` file. Alternatively, explicitly request the `anyio_backend` fixture in your async test function signatures.
affects: All versions of `anyio` with pytest integration.
gotchaConflicts can arise if `pytest-asyncio` is installed and configured to use `asyncio_mode = 'auto'` simultaneously with `anyio`'s plugin, as both attempt to auto-detect and run async tests.fixIf `pytest-asyncio` is installed, remove `asyncio_mode` from your `pytest` configuration to allow `pytest-asyncio` to use its default strict mode, preventing conflicts with `anyio`'s auto-detection.
affects: Versions of `anyio` coexisting with `pytest-asyncio`.
Upgrade
Version history
0.0.0latest on PyPI · released Jun 29, 2021
Audit
Dependencies
anyiorequiredThe pytest integration is part of the core 'anyio' library.
pytestrequiredRequired testing framework.