Skip to main content

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


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.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

pytest_aiohttp-1.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_aiohttp-1.1.0.tar.gz.

File metadata

  • Download URL: pytest_aiohttp-1.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pytest_aiohttp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 147de8cb164f3fc9d7196967f109ab3c0b93ea3463ab50631e56438eab7b5adc
MD5 890d8b15de35e7febed2fae98525480a
BLAKE2b-256 724bd326890c153f2c4ce1bf45d07683c08c10a1766058a22934620bc6ac6592

See more details on using hashes here.

File details

Details for the file pytest_aiohttp-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_aiohttp-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f39a11693a0dce08dd6c542d241e199dd8047a6e6596b2bcfa60d373f143456d
MD5 8555dd02d61c7fb56ee8a0e05361ec52
BLAKE2b-256 ba0fe6af71c02e0f1098eaf7d2dbf3ffdf0a69fc1e0ef174f96af05cef161f1b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page