pytest-anyio (DEPRECATED: Plugin built into anyio)

0.0.0 · deprecated · verified Wed Apr 15

This package is obsolete. The pytest plugin for AnyIO is built directly into the `anyio` library itself, meaning `pytest-anyio` does not need to be installed. The PyPI entry for `pytest-anyio` serves primarily as a redirect to this information. AnyIO provides a robust asynchronous networking and concurrency library compatible with asyncio and Trio, with its pytest plugin facilitating asynchronous test writing and fixture management.

Warnings

Install

Imports

Quickstart

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'

view raw JSON →