{"id":2232,"library":"pytest-aiohttp","title":"pytest-aiohttp","description":"pytest-aiohttp is a pytest plugin that provides useful fixtures for testing aiohttp applications. It simplifies the creation and interaction with aiohttp servers and clients within your pytest test suite. The current version is 1.1.0 and releases are typically made as needed, often following updates to `aiohttp` or `pytest`.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/aio-libs/pytest-aiohttp","tags":["pytest","aiohttp","testing","asyncio","plugin"],"install":[{"cmd":"pip install pytest-aiohttp","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core functionality for creating and testing aiohttp applications.","package":"aiohttp","optional":false},{"reason":"The base test framework this plugin extends.","package":"pytest","optional":false},{"reason":"Provides asyncio support for pytest, including the necessary event loop handling for async tests.","package":"pytest-asyncio","optional":false}],"imports":[],"quickstart":{"code":"import pytest\nfrom aiohttp import web\n\n# test_app.py\n\n@pytest.fixture\nasync def cli(aiohttp_client):\n    \"\"\"Client fixture that returns a test client for your aiohttp application.\"\"\"\n    app = web.Application()\n    async def hello_handler(request):\n        return web.Response(text=\"Hello from aiohttp app!\")\n    app.router.add_get('/', hello_handler)\n    return await aiohttp_client(app)\n\nasync def test_hello_world(cli):\n    \"\"\"Test that the application responds correctly.\"\"\"\n    resp = await cli.get('/')\n    assert resp.status == 200\n    text = await resp.text()\n    assert 'Hello from aiohttp app!' in text\n","lang":"python","description":"To use `pytest-aiohttp`, you need to configure `pytest-asyncio` in your `pytest.ini` (or `pyproject.toml`). A minimal `pytest.ini` might look like this:\n\n```ini\n[pytest]\nasyncio_mode = auto\n```\n\nThis setup automatically handles the asyncio event loop. The example demonstrates defining an `aiohttp` application within a fixture and then using the `aiohttp_client` fixture (provided by `pytest-aiohttp`) to create a test client for your app, which can then be used in your async test functions."},"warnings":[{"fix":"Remove the `loop` fixture from your test function signatures. Instead, use standard `asyncio` module functions like `asyncio.get_event_loop()` if you need to interact with the event loop directly, or rely on `pytest-asyncio` to manage it implicitly.","message":"The `loop` fixture was removed in version 1.0.0. If your tests explicitly depended on `loop` for asyncio event loop access, you should now use `asyncio.get_event_loop()` or `asyncio.current_task()` where appropriate.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade your Python environment to version 3.9 or higher. Alternatively, if upgrading Python is not an option, you must stick to `pytest-aiohttp` versions older than 1.0.0 (e.g., `0.4.0`).","message":"Python 3.7 and 3.8 support was dropped in version 1.0.0. Users on these Python versions must upgrade to Python 3.9 or newer to use `pytest-aiohttp` v1.0.0 and later.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Create a `pytest.ini` file in your project root (or configure `pyproject.toml`) and add the line `asyncio_mode = auto` under the `[pytest]` section. For example:\n```ini\n[pytest]\nasyncio_mode = auto\n```","message":"You must configure `pytest-asyncio` by adding `asyncio_mode = auto` to your `pytest.ini` or `pyproject.toml` file. Without this, your async tests using `pytest-aiohttp` fixtures will not run correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure your `pytest` installation meets the requirements specified by `pytest-aiohttp`. Check the `install_requires` section on the `pytest-aiohttp` PyPI page or its `setup.py`/`pyproject.toml` for the exact `pytest` version bounds.","message":"`pytest-aiohttp` has specific `pytest` version requirements. For example, `pytest-aiohttp>=1.0.0` requires `pytest>=7.0.0`. Using an incompatible version of `pytest` can lead to unexpected errors or fixtures not being discovered.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}