{"id":6824,"library":"pytest-anyio","title":"pytest-anyio (DEPRECATED: Plugin built into anyio)","description":"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.","status":"deprecated","version":"0.0.0","language":"en","source_language":"en","source_url":"https://github.com/graingert/pytest-anyio","tags":["pytest","anyio","async","testing","asyncio","trio","plugin","deprecated"],"install":[{"cmd":"pip install anyio pytest","lang":"bash","label":"Install AnyIO and pytest"}],"dependencies":[{"reason":"The pytest integration is part of the core 'anyio' library.","package":"anyio","optional":false},{"reason":"Required testing framework.","package":"pytest","optional":false}],"imports":[{"note":"The plugin is integrated into 'anyio'; access markers and fixtures via 'pytest' directly after installing 'anyio'.","wrong":"from pytest_anyio import anyio_backend","symbol":"pytest.mark.anyio","correct":"import pytest\n# ... then use @pytest.mark.anyio on async test functions or pytestmark = pytest.mark.anyio"},{"note":"The 'anyio_backend' fixture is automatically provided by the 'anyio' pytest plugin when 'anyio' is installed.","symbol":"anyio_backend (fixture)","correct":"def test_my_async_function(anyio_backend): ..."}],"quickstart":{"code":"import pytest\nimport anyio\n\n# Option 1: Mark individual async test functions\n@pytest.mark.anyio\nasync def test_async_function():\n    await anyio.sleep(0.001)\n    assert True\n\n# Option 2: Mark all async test functions in a module\npytestmark = pytest.mark.anyio\n\nasync def test_another_async_function_module_wide():\n    await anyio.sleep(0.001)\n    assert True\n\n# Option 3: Use the anyio_backend fixture (often implicitly, or for custom backend control)\nasync def test_with_anyio_backend_fixture(anyio_backend):\n    # 'anyio_backend' can be used to explicitly specify a backend or is implicitly available\n    # For example, to run only on 'asyncio':\n    # @pytest.mark.parametrize('anyio_backend', ['asyncio'])\n    # async def test_on_asyncio_only(anyio_backend):\n    await anyio.sleep(0.001)\n    assert True\n\n# Example of an asynchronous fixture\n@pytest.fixture\n@pytest.mark.anyio\nasync def async_data():\n    # Simulate async setup\n    await anyio.sleep(0.001)\n    yield {'key': 'value'}\n    # Simulate async teardown\n    await anyio.sleep(0.001)\n\nasync def test_using_async_fixture(async_data):\n    assert async_data['key'] == 'value'","lang":"python","description":"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`."},"warnings":[{"fix":"Uninstall `pytest-anyio` if present (`pip uninstall pytest-anyio`) and ensure you have `anyio` (>=3.0.0) and `pytest` installed (`pip install anyio pytest`).","message":"The `pytest-anyio` package is deprecated and should NOT be installed. Its functionality was absorbed into the `anyio` library itself.","severity":"breaking","affected_versions":"All versions (from 0.0.0 onwards)"},{"fix":"Use `@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.","message":"Asynchronous 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.","severity":"gotcha","affected_versions":"All versions of `anyio` with pytest integration."},{"fix":"If `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.","message":"Conflicts 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.","severity":"gotcha","affected_versions":"Versions of `anyio` coexisting with `pytest-asyncio`."}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}