본문으로 건너뛰기
cccskills
무료GitHub에 공개

python-testing-strategies

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md2.9 KB
  • examples.md4.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Python Testing Strategies — Quick Reference

Setup (CRITICAL)

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.

Test Client

Use httpx.AsyncClient + ASGITransport — never TestClient for async tests.

See examples.md for client fixture setup.

Required Coverage Per Endpoint

  1. Happy path (create, read, update, delete)
  2. Not found (404)
  3. Validation error (422)
  4. Auth failure (401) — if protected
  5. Soft delete — deleted records not returned

Test Naming

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

Test Data Factories

Use simple factory functions with sensible defaults. Override only what the test cares about.

See examples.md for factory patterns.

Running Tests

pytest                           # All tests
pytest tests/test_items.py       # One file
pytest -k "test_create"          # By name pattern
pytest --tb=short -q             # Quiet output

Gotchas

  • 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.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Creates RPC-style endpoint following layered architecture (Controller → Manager → Repository). Use when creating new API endpoints or CRUD operations.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

c0x12c/ai-toolkit1082026년 6월 18일 업데이트

Write blog posts, guides, tutorials, and long-form content. Sounds like a real person, not AI. Use when the user wants polished written content.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

c0x12c/ai-toolkit1082026년 6월 18일 업데이트

Design RPC-style APIs with layered architecture (Controller → Manager → Repository). Use when creating new API endpoints, designing API contracts, or reviewing API patterns.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

c0x12c/ai-toolkit1082026년 6월 18일 업데이트

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

c0x12c/ai-toolkit1082026년 6월 18일 업데이트

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

c0x12c/ai-toolkit1082026년 6월 18일 업데이트

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

c0x12c/ai-toolkit1082026년 6월 18일 업데이트

c0x12c의 스킬 모두 보기

이 스킬의 문제 신고