Creates RPC-style endpoint following layered architecture (Controller → Manager → Repository). Use when creating new API endpoints or CRUD operations.
中文简介正在准备中。当前显示原文说明。
Testing patterns for FastAPI with pytest-asyncio, httpx AsyncClient, fixtures, and test data factories. Use when writing tests, setting up test infrastructure, or improving coverage in a FastAPI project.
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
Set asyncio_mode = "auto" in pyproject.toml to auto-detect async tests without markers. (The default "strict" mode also works if you mark tests with @pytest.mark.asyncio.)
See examples.md for the complete conftest.py and pyproject.toml setup.
Use httpx.AsyncClient + ASGITransport — never TestClient for async tests.
See examples.md for client fixture setup.
async def test_create_item(): # Happy path
async def test_create_item_missing_name(): # Validation
async def test_get_item_not_found(): # 404
async def test_get_item_soft_deleted(): # Soft delete
Use simple factory functions with sensible defaults. Override only what the test cares about.
See examples.md for factory patterns.
pytest # All tests
pytest tests/test_items.py # One file
pytest -k "test_create" # By name pattern
pytest --tb=short -q # Quiet output
Missing asyncio_mode = "auto" silently breaks everything. Tests appear to pass (0 collected) or hang indefinitely. Add [tool.pytest.ini_options] asyncio_mode = "auto" to pyproject.toml before writing any async test. This is the #1 cause of "my tests don't run."
TestClient and AsyncClient are not interchangeable. TestClient (from Starlette) is synchronous — it blocks. AsyncClient (from httpx) is async — it uses the event loop. If your app uses async def routes with await, you must use AsyncClient with ASGITransport. Using TestClient may hide async bugs because it runs synchronously.
Database state leaks between tests without proper cleanup. Each test needs a clean database. Use an autouse=True fixture that creates/drops tables, or truncate between tests. Without this, test order matters and random failures appear in CI.
response.json() returns snake_case from FastAPI by default. If your Pydantic models use alias_generator, the JSON keys may differ from your Python field names. Always assert against the actual JSON keys, not the Python attribute names.
Forgetting to await in async tests gives confusing errors. If you see <coroutine object ...> in test output instead of actual data, you forgot an await. Every client.get(), client.post(), etc. must be awaited.
还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Creates RPC-style endpoint following layered architecture (Controller → Manager → Repository). Use when creating new API endpoints or CRUD operations.
中文简介正在准备中。当前显示原文说明。
Write blog posts, guides, tutorials, and long-form content. Sounds like a real person, not AI. Use when the user wants polished written content.
中文简介正在准备中。当前显示原文说明。
Design RPC-style APIs with layered architecture (Controller → Manager → Repository). Use when creating new API endpoints, designing API contracts, or reviewing API patterns.
中文简介正在准备中。当前显示原文说明。
Run a structured brainstorm session for startup ideas. Takes a theme or problem and generates ideas with quick gut-checks. Use when the user wants to explore a space or generate new ideas.
中文简介正在准备中。当前显示原文说明。
Run real browser QA with Playwright. Use when testing a frontend feature, verifying UI before PR, smoke testing after deploy, or investigating reported visual bugs.
中文简介正在准备中。当前显示原文说明。
CI/CD pipeline patterns for GitHub Actions, PR automation, and deployment workflows. Use when setting up CI, fixing broken pipelines, automating PR checks, or configuring deployment.
中文简介正在准备中。当前显示原文说明。