Skip to main content
Community
Q&A

Common pitfalls when using pytest-asyncio with FastAPI tests?

Ajitesh Mohanta
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?

No replies yet. Be the first to answer this question!

Join the discussion

Sign in to join the discussion

Sign in
Common pitfalls when using pytest-asyncio with FastAPI tests? — Community | QABash