Use `pytest.mark.anyio` for testing async functions
mainSince FastAPI depends on anyio, it is recommended to use pytest.mark.anyio instead of pytest.mark.asyncio for testing.
By default, anyio runs tests twice (once for trio and once for asyncio). If you are testing an application rather than a library, you should restrict the backend to a single one using an anyio_backend fixture.
import pytest
@pytest.fixture
def anyio_backend():
return "asyncio" # or "trio"
@pytest.mark.anyio
async def test_async_function():
...