pytest-aiohttp-client

Pytest `client` fixture for the Aiohttp


License
MIT
Install
pip install pytest-aiohttp-client==0.1.0

Documentation

pytest-aiohttp-client

Awesome pytest fixture for awesome aiohttp!

test Coverage Status Code style: black Python versions PyPi

Installation

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


@pytest.fixture
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!