Skip to main content

Pytest `client` fixture for the Aiohttp

Project description


Awesome pytest fixture for awesome aiohttp!

Build status Coverage Status Code style: black Python versions PyPi


Install it via pip tool:

pip install pytest-aiohttp-client

Usage example

Plugin provides api fixture, but you should define aiohttp_app fixture first:

import pytest

from my_awesome_app import make_app

def aiohttp_app() -> Application:
  return make_app()

Default decoding

Fixture will decode and return payload by default as json or bytes (depends on Content-Type header):

async def test_returns_json(api):
    got = await api.get("/json-url/")

    assert got == {"key": "value"}

async def test_returns_bytes(api):
    got = await api.get("/url/")

    assert got == b"Some text"

Status code assertions

You can assert on status code:

async def test_returns_ok(api):
    await api.get("/url/", expected_status=200)

Response result

Type as_response=True if you need ClientResponse object:

from aiohttp.client import ClientResponse

async def test_returns_response(api):
    got = await api.get("/url/", as_response=True)

    assert isinstance(got, ClientResponse)

Development and contribution

  • install project dependencies
python develop
  • install linting, formatting and testing tools
pip install -r requirements.txt
  • run tests
make test
  • run linters
make lint
  • feel free to contribute!

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-client-0.0.3.tar.gz (3.4 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page