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(loop):
    app = web.Application(loop=loop)
    app.router.add_route("GET", "/", hello)
    return app


async def test_hello(test_client):
    client = await test_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.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

pytest_aiohttp-1.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-aiohttp-1.0.0.tar.gz.

File metadata

  • Download URL: pytest-aiohttp-1.0.0.tar.gz
  • Upload date:
  • Size: 11.0 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

Hashes for pytest-aiohttp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8744295776292cb6683490be2c3fc59d9d9d5ec2df7298a29ed59bef6adcdd7a
MD5 c6ca6298c9ea488e68c5be5ab44c6bb3
BLAKE2b-256 2e327578fa58132d5f597fd3ac25f1aec910fb5ba45524c6864d77450cc2e51f

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: pytest_aiohttp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 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

Hashes for pytest_aiohttp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f5279a8ac316625b0a681cad6a6c3aa6daa9cabe98de93a2cfbd470e692861f
MD5 6e2b7aab6d5a82ec24b120af946662e0
BLAKE2b-256 4583b310370af163577ba97dcefe43990dce3d67278c11f1dea15b50177922c0

See more details on using hashes here.

Provenance

Supported by

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