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
Built Distribution
File details
Details for the file pytest-aiohttp-1.0.1.tar.gz
.
File metadata
- Download URL: pytest-aiohttp-1.0.1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56239a3e0abc393d9037995b2aa04a024c5e172e17046f2ef831a293fa13ace9 |
|
MD5 | eb180447891dc8d719542fa45ec20cba |
|
BLAKE2b-256 | 03dfaa6dda3de3e5fd5728001498684f568d0e3641feca25d80aed6891384ae2 |
File details
Details for the file pytest_aiohttp-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_aiohttp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c53e93f030a46d55b40dd601170da9afd66d2e4f36fc5a4b3b3787011e7b0c93 |
|
MD5 | 24af89129b70a082f4ad954c87b783c1 |
|
BLAKE2b-256 | 3815f98234450adafbcf0fee224ce3f27b0772f5a0b703d3ad0655b88c7e8656 |