ワンクリックで
tdd-workflow
Test-driven development workflow for FastAPI + asyncpg apps. Write tests first, then implement, then refactor.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Test-driven development workflow for FastAPI + asyncpg apps. Write tests first, then implement, then refactor.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Create a new database migration for PostgreSQL. Covers file naming, SQL patterns, running, and updating dependent code.
Baseline code quality enforcer — naming conventions, import hygiene, type safety, and style rules for a FastAPI + asyncpg + PostgreSQL Python backend.
Database schema reference for the hello-world app's PostgreSQL instance. Use when writing queries, creating migrations, or debugging data issues.
Docker patterns for this project — DooD (Docker-outside-of-Docker), compose conventions, container lifecycle, and dev-box workflow.
Step-by-step checklist for adding a new API endpoint to a FastAPI + asyncpg app. Covers schema, query, route, and verification.
Project file tree and layout conventions. Use when navigating the codebase, finding where files belong, or understanding the project layout.
| name | tdd-workflow |
| description | Test-driven development workflow for FastAPI + asyncpg apps. Write tests first, then implement, then refactor. |
This skill ensures all code development follows TDD principles.
ALWAYS write tests first, then implement code to make tests pass.
httpx.AsyncClient + FastAPI TestClientAs a [role], I want to [action], so that [benefit]
Example:
As an API consumer, I want to POST /api/events to record events,
so that I can track usage over time.
import pytest
from httpx import AsyncClient, ASGITransport
from main import app
@pytest.mark.asyncio
async def test_create_event_returns_201():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
resp = await client.post("/api/events", json={"name": "page_view"})
assert resp.status_code == 201
assert "id" in resp.json()
@pytest.mark.asyncio
async def test_create_event_validates_input():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
resp = await client.post("/api/events", json={})
assert resp.status_code == 422
python -m pytest tests/ -v
Write just enough code to make tests pass. No more.
python -m pytest tests/ -v
Improve code quality while keeping tests green:
from unittest.mock import AsyncMock, MagicMock
@pytest.fixture
def mock_pool():
pool = AsyncMock(spec=asyncpg.Pool)
pool.fetchrow.return_value = {"id": 1, "hits": 42}
pool.fetch.return_value = [{"id": 1, "hits": 42}]
return pool
@pytest.fixture
async def test_pool():
pool = await asyncpg.create_pool(os.environ["TEST_DATABASE_URL"])
await pool.execute("DELETE FROM hello_counter")
yield pool
await pool.close()
from fastapi.testclient import TestClient
def test_read_hits():
with TestClient(app) as client:
resp = client.get("/api")
assert resp.status_code == 200
assert "hits" in resp.json()
project/
├── main.py
├── queries.py
├── schemas.py
├── tests/
│ ├── conftest.py # Shared fixtures
│ ├── test_endpoints.py # API integration tests
│ ├── test_queries.py # DB query unit tests
│ └── test_schemas.py # Pydantic validation tests
test_hit_increments_counter, not test_1