tests

A testing guide for code in unit, integration, and end-to-end test folders. Unit tests check small pieces, integration tests check connected parts, and end-to-end tests check complete user or API flows.

In plain words
What is it for?
Use it when creating or extending tests for use cases, API endpoints, data mutations, request fields, optional loading, roles, and validation boundaries.
Why use it?
It targets bugs that can be missed when a test only checks that a request returned successfully instead of checking the saved result and exact scenario.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/ocbunknown/fastapi-claude-template/tests
Any agent
npx skills add ocbunknown/fastapi-claude-template --skill tests
Clone the repo
git clone --depth 1 https://github.com/ocbunknown/fastapi-claude-template

Made for: Claude Code, Codex.

Per session 115 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,687 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00115 $0.05687
Opus 5 $0.00057 $0.02844
Sonnet 5 $0.00023 $0.01137
Haiku 4.5 $0.00012 $0.00569

Measured 3d ago against content hash 0d616946bfe6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

tests scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/tests/SKILL.md · 430 lines

How it starts

The opening of the file, as written. The whole thing — 430 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Writing tests (tests/unit/, tests/integration/, tests/e2e/)

Tests without rules drift into ceremony — "test exists, test passed, shipping". Real bugs this repo shipped because nobody had a test that exercised the exact scenario:

  1. UserResult.model_validate(orm_user) in update.py / create.py / permission.py — crashed with MissingGreenlet on PATCH/POST. Not caught because the e2e tests only hit GET.
  2. UpdateUserRequest had only password field while AdminUpdateUser contract had password + active + role_uuid — PATCH silently dropped active and role_uuid (Pydantic extra="ignore"), returned 200, and did nothing. Not caught because no test verified that the mutation persisted via a follow-up GET.
  3. select_many without loads=role triggered MissingGreenlet. Caught only because an explicit test_select_users_omits_role_by_default test existed. Other endpoints had no such test.

Every "why didn't the tests catch this" answer has the same root: the scenario was never tested. This skill lists the scenarios that must exist.

Pick the right layer — don't cross them

Layer What it tests What it uses Typical runtime
tests/unit/ Pure logic: use cases, validators, helpers, contracts MagicMock/AsyncMock DBGateway, FakeHasher, FakeJWT, FakeStrCache from tests/fakes.py < 2s for the whole folder
tests/integration/ Real I/O: repositories against Postgres, Redis adapters, NATS brokers Session-scoped testcontainers (Postgres/Redis/NATS), per-test outer-transaction rollback 3–10s
tests/e2e/ Full HTTP stack: endpoint → contract → request bus → use case → repo → DB Real app wired via Dishka, httpx.AsyncClient + ASGITransport 5–15s

Hard rules:

  • Unit tests never touch I/O. No await database.X.create(...) against a real DB — that's integration.
  • Integration tests never go through HTTP. If you want to test the endpoint wiring, that's e2e.
  • E2E tests never replace unit tests. Unit tests cover branches fast; e2e tests cover a few happy/sad paths against the real stack. Don't try to cover every validation edge case in e2e — that belongs in unit (for Pydantic contracts) and integration (for DB constraints).

Read the full file on GitHub · 430 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 430 lines · 115 tokens per session scan A 0d616946bfe6

Subscribe to this mod's changes

tests is a skill published in the GitHub repository ocbunknown/fastapi-claude-template (32 stars, last pushed 4mo ago), licensed MIT. It adds 115 tokens to every session and 5,687 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.