Skip to main content

Pytest `client` fixture for the Aiohttp

Project description

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!

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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pytest_aiohttp_client-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_aiohttp_client-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure

File hashes

Hashes for pytest_aiohttp_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ae2dad8e3db052b3fd0296ce8d542d7f04a911f23f2d82f2777021815e88a708
MD5 bc077ee4109daf23f5babcac1eb2156d
BLAKE2b-256 16b72fd2ac57a0ceb1ea6d75cd5f82122469225f81e33d57745c039a3389ce4a

See more details on using hashes here.

File details

Details for the file pytest_aiohttp_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_aiohttp_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b20ed9234d3d19493c5a02ff9ccb97a30766f01c11ddd3502b73b665334844f1
MD5 c29acdfd5c0464939ebf2a55e6b9b225
BLAKE2b-256 54ea8b8bd7383a0a4f11b6356e6a0b49f230e901805f5bf44747d32ce7f4fc2d

See more details on using hashes here.

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