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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_aiohttp-1.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_aiohttp-1.1.1.tar.gz
Algorithm Hash digest
SHA256 3aa9c9fe26e543eaccc7eb0add381c685ba3ed3e2fed0af74540f63bcd31458d
MD5 0ef085874c45de8a88c8d5b837d14d6c
BLAKE2b-256 514dc6621fc79022f6c84a806e23d9b7eca24fae4f3ee779219bbe524339d666

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_aiohttp-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytest_aiohttp-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f293441ad4f8446a1e12257130c26c7de03a615c2a5572a8cb046e5b3b4e5211
MD5 ddd54f8f57c6e34e44c7ef8dfd24f93b
BLAKE2b-256 fab05056ed4c3f68a4db2b4a39fb0ec61b1e4cf1d89ee14effe5261cc587264c

See more details on using hashes here.

Supported by

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