Skip to main content

Pytest `client` fixture for the Aiohttp

Project description


Awesome pytest fixture for awesome aiohttp!

test Coverage Status Code style: black Python versions PyPi


Install it via pip tool:

pip install pytest-aiohttp-client

or Poetry:

poetry add yandex-geocoder

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

First of all you should install Poetry.

  • install project dependencies
make install
  • run linters
make lint
  • run tests
make test
  • 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.1.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

pytest_aiohttp_client-0.1.0-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

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