litestar-testing
Installation
SKILL.md
litestar-testing
Litestar-specific testing patterns built on pytest + anyio. Covers:
TestClientvsAsyncTestClient— constructor options, lifespan, and when to use eachcreate_test_clientandcreate_async_test_client— inline app factories for isolated handler/controller tests@pytest.mark.anyiosetup andpytest-asynciocoexistence rules- App + lifespan fixtures (
on_startup/on_shutdown/lifespan) - Mocking Guards and overriding DI dependencies (native
Provideand DishkaProvider) - Session testing with
set_session_dataandget_session_data - WebSocket testing with
websocket_connectandWebSocketTestSession - Unit-testing Guards and dependencies with
RequestFactory - Live server subprocess testing with
subprocess_async_clientandsubprocess_sync_client - Integration with
pytest-databases(see../pytest-databases/SKILL.md) andpolyfactory(see../polyfactory/SKILL.md) - Autowire discovery and cache isolation (see
../litestar-autowire/references/testing.md)
For JS-side testing (Vitest, Testing Library, Playwright), use the upstream Vitest docs and Litestar's own JS examples. Out of scope here.