Pytest plugin for aiohttp support
Project description
pytest plugin for aiohttp support
The library provides useful fixtures for creation test aiohttp server and client.
Installation
$ pip install pytest-aiohttp
Add asyncio_mode = auto line to pytest configuration (see pytest-asyncio modes for details). The plugin works with strict mode also.
Usage
Write tests in pytest-asyncio style using provided fixtures for aiohttp test server and client creation. The plugin provides resources cleanup out-of-the-box.
The simple usage example:
from aiohttp import web
async def hello(request):
return web.Response(body=b"Hello, world")
def create_app():
app = web.Application()
app.router.add_route("GET", "/", hello)
return app
async def test_hello(aiohttp_client):
client = await aiohttp_client(create_app())
resp = await client.get("/")
assert resp.status == 200
text = await resp.text()
assert "Hello, world" in text
See aiohttp documentation <https://docs.aiohttp.org/en/stable/testing.html#pytest> for more details about fixtures usage.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-aiohttp-1.0.5.tar.gz
.
File metadata
- Download URL: pytest-aiohttp-1.0.5.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 880262bc5951e934463b15e3af8bb298f11f7d4d3ebac970aab425aff10a780a |
|
MD5 | 018154c8bffaa71a76780e51c7cbe66f |
|
BLAKE2b-256 | 28ad7915ae42ca364a66708755517c5d669a7a4921d70d1070d3b660ea716a3e |
File details
Details for the file pytest_aiohttp-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: pytest_aiohttp-1.0.5-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63a5360fd2f34dda4ab8e6baee4c5f5be4cd186a403cabd498fced82ac9c561e |
|
MD5 | 4d9a24f7dfce0e6d5c607c4380cf1d3b |
|
BLAKE2b-256 | 9aa76e50ba2c0a27a34859a952162e63362a13142ce3c646e925b76de440e102 |