litestar-testing
Installation
SKILL.md
Testing
Execution Workflow
- Choose the right client shape first:
TestClient,AsyncTestClient,create_test_client, or subprocess live-server helpers. - Build fixtures with deterministic configuration, dependencies, and lifecycle boundaries.
- Isolate external I/O with injected fakes or mocked dependencies instead of monkeypatching internals.
- Assert full contracts: status code, body, headers, cookies, side effects, and failure payload shape.
- Cover error paths deliberately, including validation failures, app-level exception mappings, event-listener failures, layered override precedence, and schema/docs regressions.
Core Rules
- Keep tests deterministic in time, randomness, and I/O.
- Use
AsyncTestClientwhen tests, fixtures, and app resources must share the same event loop. - Use
create_test_clientfor isolated handler tests or small app subsets. - Prefer dependency injection and fake services over patching transport-layer code.
- Assert stable error contracts, not just that an exception occurred.
- Reset overrides and fixture state between tests.
- Use live-server subprocess helpers when the in-process client cannot emulate the transport correctly.