一键导入
test-quality
Enforce test quality standards — coverage, shared fixtures, no magic strings. Use this when writing, reviewing, or refactoring tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Enforce test quality standards — coverage, shared fixtures, no magic strings. Use this when writing, reviewing, or refactoring tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
E2E test skill that confirms plugin loading works.
Templates and process for creating devcontainer configurations. Use this when setting up a new project, adding devcontainer support, or creating devcontainers for worktrees.
Procedure for creating a git worktree and devcontainer for a new task. Use this when starting a new development task.
Cross-model code review before every PR. Use this after code is written and before pushing.
Mandatory checklist before starting implementation. Use this before writing code for any non-trivial task.
Production Dockerfile and container runtime security checklist. Use this when building Docker/Podman images or configuring container deployments.
| name | test-quality |
| description | Enforce test quality standards — coverage, shared fixtures, no magic strings. Use this when writing, reviewing, or refactoring tests. |
--cov-fail-under=90 in pyproject.toml:
[tool.pytest.ini_options]
addopts = "--cov=my_package --cov-report=term-missing --cov-fail-under=90"
pytest --cov-report=term-missing to identify uncovered lines before submitting.❌ Bad:
def test_webhook(client):
resp = client.post("/webhook", headers={"X-Gitlab-Token": "test-secret"}, json={
"object_kind": "merge_request",
"user": {"id": 1, "username": "jdoe"},
...
})
✅ Good:
from tests.conftest import HEADERS, MR_PAYLOAD
def test_webhook(client):
resp = client.post("/webhook", headers=HEADERS, json=MR_PAYLOAD)
Rules:
conftest.py or a dedicated tests/constants.py.GITLAB_URL, WEBHOOK_SECRET, MR_PAYLOAD.# tests/conftest.py — single source of truth for test data
# Constants
GITLAB_URL = "https://gitlab.example.com"
GITLAB_TOKEN = "test-token"
WEBHOOK_SECRET = "test-secret"
HEADERS = {"X-Gitlab-Token": WEBHOOK_SECRET}
# Factory functions — tests override only what they care about
def make_settings(**overrides):
defaults = {"gitlab_url": GITLAB_URL, "gitlab_token": GITLAB_TOKEN, ...}
return Settings(**(defaults | overrides))
def make_mr_payload(**attr_overrides):
payload = {**MR_PAYLOAD}
if attr_overrides:
payload["object_attributes"] = {**payload["object_attributes"], **attr_overrides}
return payload
# Shared fixtures
@pytest.fixture
def env_vars(monkeypatch):
monkeypatch.setenv("GITLAB_URL", GITLAB_URL)
monkeypatch.setenv("GITLAB_TOKEN", GITLAB_TOKEN)
monkeypatch.setenv("GITLAB_WEBHOOK_SECRET", WEBHOOK_SECRET)
| Anti-pattern | Fix |
|---|---|
| Same env var setup in 3+ test files | Move to conftest.py env_vars fixture |
| Payload dict copy-pasted between files | Single MR_PAYLOAD constant in conftest |
client fixture duplicated | Single shared fixture in conftest |
Inline "https://gitlab.example.com" | GITLAB_URL constant |
Testing that pydantic.ValidationError is raised by Pydantic | Test our validation logic, not Pydantic itself |
No --cov-fail-under in config | Add to pyproject.toml immediately |
| Test passes with a no-op implementation of your code | You're testing the library, not your code — delete it |
If your test would still pass after replacing your code with a no-op, it's verifying a third-party library works — not that your code is correct. Common examples:
httpx.post makes a request (tests httpx, not your API client)Instead, test what your code does with the library: correct labels on metrics, correct validation error messages, correct URL construction.
| Layer | What to test | Mocking | Location |
|---|---|---|---|
| Unit | Single function/class logic | Mock all deps | tests/test_<module>.py |
| Integration | Module wiring (webhook → orchestrator → poster) | Mock external services | tests/test_integration.py |
| E2E | Full service with real services | None or containers | tests/test_e2e.py or scripts/ |
Before submitting tests, verify:
conftest.pypytest --cov-report=term-missing shows ≥90% coverageFor epics or features touching infrastructure, security, or external integrations: create a gate issue requiring E2E verification before the epic closes. Unit tests alone are insufficient — they mock the boundaries where bugs actually hide.
Pattern:
test(e2e): live integration test before closing epic #NExample result documentation:
## E2E Results — Docker DinD Review
- Webhook received: 18:01:53 UTC
- Review completed: 18:03:24 UTC (91s)
- 3 inline comments posted on MR !5
- Findings: pickle deserialization (CWE-502), missing error handling