Awesome pytest fixture for awesome aiohttp!
Install it via pip tool:
pip install pytest-aiohttp-clientor Poetry:
poetry add yandex-geocoderPlugin 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()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"You can assert on status code:
async def test_returns_ok(api):
await api.get("/url/", expected_status=200)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)First of all you should install Poetry.
- install project dependencies
make install- run linters
make lint- run tests
make test- feel free to contribute!