Pytest async tests and fixtures

Async tests and fixtures Pytest already has the official pytest-asyncio plugin which allows you to write async tests and fixtures. According to pytest-asyncio docs, you can have an async test with an async fixture like this: from typing import Any, AsyncGenerator import pytest import pytest_asyncio from httpx import AsyncClient @pytest_asyncio.fixture async def client() -> AsyncGenerator[AsyncClient, Any]: async with AsyncClient() as c: yield c @pytest.mark.asyncio async def test_api_call(client: AsyncClient) -> None: response = await client....

June 29, 2023 · 2 min · 363 words · Amin