بنقرة واحدة
testing
Testing guidance for pytest, Jest/Vitest, Go, and TDD. Use when writing tests or improving coverage.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Testing guidance for pytest, Jest/Vitest, Go, and TDD. Use when writing tests or improving coverage.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Promotes recurring feedback into the right skill, then guides /compact at phase boundaries.
Methodical debugging with evidence and hypothesis testing. Use when troubleshooting fails or root cause is unclear.
Create new skills, commands, hooks, or subagents. Use when adding capabilities to Claude Code or Cursor.
PostgreSQL patterns for queries, schema, indexing, security. Use when writing SQL, designing schema, or adding indexes.
Reviews a GitHub PR diff for correctness, security, tests, architecture. Use when asked to review a PR or pull request.
Orchestrates the Ralph pipeline (spec-interview → PRD → execute). Use for features needing autonomous implementation.
| name | testing |
| description | Testing guidance for pytest, Jest/Vitest, Go, and TDD. Use when writing tests or improving coverage. |
<essential_principles>
Universal test foundations — test pyramid, AAA structure, naming-as-behavior-sentence, ~80% coverage default, test independence, behavior-not-implementation — live in ~/.claude/rules/testing/RULE.md (with deep-dives in ~/.claude/rules/testing/references/). Read those first; the pytest-specific add-ons (real objects for domain types, factories in conftest, headers-asserted-too, module-level mutable state) live in <pytest_principles> below.
</essential_principles>
<pytest_principles>
When writing pytest (Python):
MagicMock for a domain object silently accepts any attribute access and lets schema breaks pass — production-only failure mode. Mocks remain ok for system boundaries (DB session, HTTP client, scraper, logger).make_* factory fixture to tests/conftest.py, not a private _make_* helper inside a single test file. Use via dependency injection: def test_x(make_main_table_client): .... The factory takes **overrides so each test can customize.tests/test_<module>.py covering everything in app/.../<module>.py over splitting by concern (e.g. test_<module>_report.py + test_<module>_schedules.py). Split files drift apart, duplicate helpers, and hide shared fixtures. Consolidate before adding new tests when a module already has multiple test files.from foo import Bar inside a test body.conftest.py before creating new onesresponse.status_code AND any contract-meaningful headers (X-Cache, Retry-After, WWW-Authenticate, content-type, etc.) — not just the body shape. Weak assertions like status != 200 or X-Cache != "HIT" miss real bugs (e.g. a 201 flattened to 200 on cache replay, or a header silently dropped). Pin the exact value.assert set(FIXTURE_STATUSES) == {s.value for s in StatusEnum}) that fails when the schema drifts EITHER WAY. A subset assertion (<=) only catches harness-has-invalid-value drift; it silently passes when the schema adds a value the harness doesn't cover (verified: a schema added UNPLUGGED=13, the harness still had [1..12], every subset test stayed green, the harness silently stopped covering one production state). A standalone list of "looks right" values is a silent contract test for a contract that doesn't exist — and pydantic / DB constraints will reject the drift in production while every unit test passes.assert set(response.keys()) == set(Schema.__fields__.keys()). Column-iteration drift-guard loops (for col in __table__.columns: assert getattr(row, col.name) is not None) are additive — they catch newly-added fields being dropped, but they silently pass when TWO fields swap mappings because both still hold some value. Three complementary layers: per-field pins the intended value, set-equality catches additions, the drift loop catches removals. Any partial spot-check ships the wrong-value bug to prod.event_loop fixture scope to your async singletons' lifetime. If the suite touches any process-cached async resource — a SQLAlchemy async engine per client_name, a pooled HTTP client, a kafka producer, a redis client — override pytest-asyncio's default function-scoped event_loop with a session-scoped fixture in conftest.py (and set asyncio_default_fixture_loop_scope = session in pytest.ini for pytest-asyncio ≥ 0.24). Otherwise pytest-asyncio spins up a new loop per test, the singleton stays attached to the FIRST loop, and later tests blow up with RuntimeError: got Future <...> attached to a different loop — a lifecycle mismatch that looks like a race or flake. Rule of thumb: fixture scope must be ≥ the resource's cache scope. If the singleton is torn down between tests (via a fresh-per-function fixture), function scope is fine — the mismatch, not either scope, is the bug.</pytest_principles>
| Language/Task | Reference | |---------------|-----------| | Python pytest patterns and examples | `languages/python/testing.md` | | Python mocking patterns | `languages/python/testing.md` | | TypeScript/JS testing | `languages/typescript/testing.md` | | Node.js testing | `languages/nodejs/testing.md` | | Go testing | `languages/go/testing.md` | | C++ testing | `languages/cpp/testing.md` | | Integration test infrastructure (LocalStack, Docker Compose) | `references/localstack-integration.md` | | LocalStack AWS service configs (S3, SQS, DynamoDB, Secrets Manager) | `references/localstack-aws-services.md` | | Docker Compose test patterns, container management | `references/docker-compose-testing.md` | | TDD workflow (red-green-refactor) | `workflows/tdd.md` |<success_criteria>
<fixing_tests>
When invoked to fix failing tests (not write new ones):
@pytest.mark.skip once the test is passing</fixing_tests>