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(await 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
pytest-aiohttp-1.0.2.tar.gz
(11.1 kB
view hashes)
Built Distribution
Close
Hashes for pytest_aiohttp-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f775b523c3ad6da0e267fdfeb51f004b46f08c14ac809d25f1a15559969fec76 |
|
MD5 | a0de67303e87864828b32d9decc3f338 |
|
BLAKE2b-256 | 4dab5c175528ad5ada35014955d3eb31a6ea357b7d3e7b85c044294e0e4b7ce1 |