{"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`.","language":"python","status":"active","last_verified":"Thu Apr 09","install":{"commands":["pip install pytest-aiohttp"],"cli":null},"imports":[],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":"2026-04-25","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]},"compatibility":null}