advanced-alchemy
Use when working with advanced_alchemy, alembic/, SQLAlchemyAsyncRepositoryService, SQLAlchemyAsyncConfig, repository_type,…
Use when working with test_*.py, conftest.py, litestar.testing, TestClient, AsyncTestClient, create_test_client, create_async_test_client, anyio, Guard mocks, or DI overrides. Not for generic pytest.
Claude Code
$ npx -y skills add litestar-org/litestar-skills --skill litestar-testing --agent claude-code
Codex
$ npx skills add litestar-org/litestar-skills --skill litestar-testing -a codex -y
Cursor
$ npx skills add litestar-org/litestar-skills --skill litestar-testing -a cursor -y
Gemini CLI
$ npx skills add litestar-org/litestar-skills --skill litestar-testing -a gemini-cli -y
GitHub Copilot
$ npx skills add litestar-org/litestar-skills --skill litestar-testing -a github-copilot -y
OpenCode
$ npx skills add litestar-org/litestar-skills --skill litestar-testing -a opencode -y
Windsurf
$ npx skills add litestar-org/litestar-skills --skill litestar-testing -a windsurf -y
name: litestar-testing description: "Use when working with test_*.py, conftest.py, litestar.testing, TestClient, AsyncTestClient, create_test_client, create_async_test_client, anyio, Guard mocks, or DI overrides. Not for generic pytest."
Litestar-specific testing patterns built on pytest + anyio. Covers:
For JS-side testing (Vitest, Testing Library, Playwright), use the upstream Vitest docs and Litestar's own JS examples. Out of scope here.
| Client | Base Class | Context Manager | Session Helpers | WebSocket Connect | | --- | --- | --- | --- | --- | | `AsyncTestClient` | `httpx.AsyncClient`, `BaseTestClient` | `async with AsyncTestClient(app=app) as client:` | `await client.set_session_data(...)` / `await client.get_session_data()` | `with await client.websocket_connect("/ws") as ws:` | | `TestClient` | `httpx.Client`, `BaseTestClient` | `with TestClient(app=app) as client:` | `client.set_session_data(...)` / `client.get_session_data()` | `with client.websocket_connect("/ws") as ws:` |
Both clients accept the same constructor parameters:
from litestar.testing import AsyncTestClient, TestClient
AsyncTestClient(
app=app,
base_url="http://testserver.local", # Must contain a dot ('.') or UserWarning is emitted
raise_server_exceptions=True, # False wraps unhandled server exceptions as HTTP 500 responses
root_path="",
backend="asyncio", # "asyncio" | "trio"
backend_options=None,
session_config=None, # Required for get_session_data() / set_session_data()
timeout=None,
cookies=None,
)Both set `follow_redirects=True` and `headers={"user-agent": "testclient"}` by default. When testing template responses, `TestClientTransport` populates `response.template` and `response.context` on the returned `httpx.Response`.
from litestar.testing import AsyncTestClient
async def test_index(async_client: AsyncTestClient) -> None:
resp = await async_client.get("/")
assert resp.status_code == 200from litestar.testing import TestClient
def test_index(client: TestClient) -> None:
resp = client.get("/")
assert resp.status_code == 200For isolated route handler, controller, or router tests without bootstrapping the full application factory, use `create_async_test_client(route_handlers=..., **litestar_and_client_kwargs)` (or `create_test_client` for sync tests). Both build a `Litestar` instance and return a configured test client.
import pytest
from litestar import get
from litestar.testing import create_async_test_client
@get("/health")
async def health_check() -> dict[str, str]:
return {"status": "ok"}
@pytest.mark.anyio
async def test_health_check() -> None:
async with create_async_test_client(route_handlers=health_check) as client:
resp = await client.get("/health")
assert resp.status_code == 200
assert resp.json() == {"status": "ok"}# conftest.py
import pytest
@pytest.fixture(scope="session")
def anyio_backend() -> str:
return "asyncio"Prefer `@pytest.mark.anyio` because Litestar's internal concurrency model is built on AnyIO. Do not mix `@pytest.mark.anyio` and `@pytest.mark.asyncio` in the same test module.
# conftest.py
from collections.abc import AsyncGenerator
import pytest
from litestar import Litestar
from litestar.testing import AsyncTestClient
from app import create_app
@pytest.fixture
async def app() -> Litestar:
return create_app()
@pytest.fixture
async def async_client(app: Litestar) -> AsyncGenerator[AsyncTestClient[Litestar], None]:
async with AsyncTestClient(app=app) as client:
yield client`async with AsyncTestClient(...)` enters `LifeSpanHandler`, firing `on_startup` / `on_shutdown` hooks and plugin `lifespan` context managers (Vite, SAQ, SQLAlchemy, Channels, etc.). Without the context manager, implicit startup emits a `DeprecationWarning` and shutdown hooks never run.
Guards are functions of `(connection: ASGIConnection, route_handler: BaseRouteHandler) -> None | Awaitable[None]`. Test the real guard with fake identity or authorization pr
Opinionated, first-party agent skills, plugins, subagents, hooks, and rules for the Litestar framework and its ecosystem — published from a single-root repository across Google Antigravity, Claude Code, Codex CLI, Cursor, OpenCode, and VS Code / Copilot.
Use when working with advanced_alchemy, alembic/, SQLAlchemyAsyncRepositoryService, SQLAlchemyAsyncConfig, repository_type,…
Use when working with litestar_autowire, AutowirePlugin, AutowireConfig, domain_packages, AutowireIntegration, AutowireLoader, or…
Use when working with uv build, hatch build, PyApp, PYAPP_*, wheel assets, GitHub release matrices, cargo-zigbuild, or…
Use when working with Dockerfile, compose, Railway, Cloud Run, GKE, systemd, Kubernetes, Terraform, deploy scripts, or…
Use when working with zensical.toml, docs/conf.py, sphinx, shibuya, litestar-sphinx-theme, mkdocstrings, Griffe, objects.inv, or…
Use when working with litestar_email, EmailPlugin, EmailConfig, EmailService, EmailMessage, SMTPConfig, ResendConfig,…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.