Q&A
Common pitfalls when using pytest-asyncio with FastAPI tests?
Ajitesh MohantaAmbassador
2w ago 1,443 0
I'm testing a FastAPI application with `pytest-asyncio` and `httpx.AsyncClient` and hitting a few rough edges.
Issues I've encountered:
- `event_loop` fixture deprecation warnings in pytest-asyncio 0.21+
- Tests passing individually but failing when run together (event loop sharing?)
- Async fixtures with `scope="session"` behaving unexpectedly
I've seen the `asyncio_mode = "auto"` recommendation but it breaks some of our sync fixtures. Is there a clean setup for FastAPI + pytest-asyncio that handles session-scoped async fixtures correctly?