audit-pytest-file
Use when reviewing one Python test file for production-readiness — runs pytest as a black-box probe and surfaces failed tests, fixture errors, slow tests, empty files, all-skipped suites, and collection failures. Trigger when the user names a single test file path to audit, asks "are these tests OK", asks for a structured pytest health check on one file, or wants to grade test signal-to-noise.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 15
- Forks
- 13
01 前言 Front Matter
- name
- audit-pytest-file
- agent
- Explore
- model
- opus-4-7
- effort
- xhigh
- context
- fork
- description
- Use when reviewing one Python test file for production-readiness — runs pytest as a black-box probe and surfaces failed tests, fixture errors, slow tests, empty files, all-skipped suites, and collection failures. Trigger when the user names a single test file path to audit, asks "are these tests OK", asks for a structured pytest health check on one file, or wants to grade test signal-to-noise.
- allowed-tools
- Bash(uv run *), Bash(pytest *), Bash(python *), Bash(test *), Read, Glob, Grep
- argument-hint
- [file]
- disable-model-invocation
- false
02 资源文件 3
- 参考文档README.md2.7 KB
- 脚本scripts/audit_pytest.py11.4 KB
- 参考文档templates/audit-report.md1.2 KB
03 SKILL.md 正文
audit-pytest-file
Goal: produce a structured audit of one Python test file by running pytest against it and surfacing defects the engineer can fix in the same pass.
Workflow
Use this checklist literally. Mark each step done before moving to the next.
-
[ ] Step 1: Plan. Read
templates/audit-report.mdso you know the output shape. Runuv run ${CLAUDE_SKILL_DIR}/scripts/audit_pytest.py --helpand confirm the flags exist. -
[ ] Step 2: Pre-flight. Run
test -f "$0" && echo ok || echo missingto confirm the file exists, thenpytest --version 2>&1 | head -1to confirm the runner is installed. If either fails, stop and tell the user (no point auditing a file pytest cannot reach). -
[ ] Step 3: Run the probe. Run exactly:
uv run ${CLAUDE_SKILL_DIR}/scripts/audit_pytest.py --file "$0" --format jsonDo not modify the command. The script returns exit code 0 (no blocking findings) or 1 (findings present). Any other code is a usage error and must be reported as-is.
-
[ ] Step 4: Validate. Parse the JSON. If
findingsis empty, write a short report saying so. Otherwise group findings bycategory. -
[ ] Step 5: Render. Use the template in
templates/audit-report.md. Fill every section. Do not invent findings the script did not produce.
Якщо файл не передано
When the user asks "audit my tests" without naming a file, do not guess. Ask one clarifying question — which file? Suggest concrete candidates first:
- The test file the user is currently editing or that recently failed in CI.
- A test file that owns a critical workflow (auth, billing, ingestion).
- A specific module's test file when the user names a module.
Ask for the path relative to the project root (tests/test_users.py), not just a test name — the probe runs pytest against a file path.
Calling the probe (rigid part)
The script is the source of truth. Run exactly the command in Step 3. Do not write your own pytest invocation, do not add -k filters, do not skip the run because "the file looks fine". Findings come from the script or they do not exist.
If the project uses a wrapped pytest (poetry, uv, custom shim), pass it explicitly: append --pytest "uv run pytest" (or --pytest "poetry run pytest") to Step 3. Default is pytest.
If a single test file legitimately takes longer than the default 60-second timeout (large fixture, integration smoke), pass --timeout 180. Do not raise it casually — the timeout exists so a hung subprocess does not freeze the audit.
Gotchas
- The script needs
uvon PATH. Ifuv runfails withcommand not found, instruct the user to install uv (https://docs.astral.sh/uv) and stop. pytestitself must be installed in the environment that imports the test file. The script delegates to whateverpytestis on PATH — it does not bundle its own copy. Ifpytest --versionfails, the user needs to install pytest in their project (pip install pytest,uv add pytest, or activate the project venv) before the audit can run.--report-logis provided by the pytest-reportlog plugin, not by core pytest. If the script reportscategory: runnerwith exit 4, the plugin is missing; tell the user topip install pytest-reportlog(oruv add --dev pytest-reportlog). Alternatively, override the runner with--pytest "uv run --with pytest --with pytest-reportlog pytest"for an ad-hoc audit that does not require touching the project's deps.- Conftest.py in parent directories will be loaded — that is pytest's normal behaviour, not a tool bug. Tests that depend on session-scope fixtures will work; tests that depend on app-level state (DB, cache, network) may fail in audit context. That failure is a finding ("test depends on external state and cannot run in isolation"), not a tool bug.
- 0 tests collected is a finding, not a tool bug. Common causes: file accidentally renamed off the
test_*.pypattern,pytestmark = pytest.mark.skipat module level, conftest filtering everything out, all tests marked@pytest.mark.skip. Surface the warning verbatim. - Slow threshold defaults to 0.5s per test. For IO-heavy or integration suites that is too aggressive — pass
--slow-threshold 5.0. Do not disable the check; raise the bar. - Output truncation: by default the JSON includes only the first 3 findings plus a
truncated: trueflag. Pass--fullif you need every finding for a long report. - Tests that print to stdout will not corrupt the audit — the report log is written to a separate file. But if a test calls
sys.exit()or kills the runner, the log will be incomplete; that surfaces as acategory: collectionerror in our output. - A failed assertion is a finding, not necessarily a defect. The script reports outcomes; you decide which matter for the user's intent. Failures in tests that were already known broken (e.g. an open bug ticket) are still worth surfacing — they belong in the report so the user can confirm the bug is still reproducing.
Output format
Use templates/audit-report.md. Keep the structure even if some sections are empty (write "no findings" instead of omitting the section).
When NOT to use this skill
- Auditing a whole
tests/directory or the project's full suite. The probe deliberately scopes to one file; for whole-project audits, use a higher-level orchestrator that calls this skill per file (or use a dedicated reporting plugin likepytest-html). - Static-only review (assertion count, AAA structure, naming conventions, mocking discipline). The probe is runtime — it sees only what pytest reports. For static review, pair with a separate AST-based skill.
- Coverage analysis. The probe does not run with
coverageenabled; it reports outcomes and durations only. For coverage gaps, runpytest --covseparately. - Flakiness detection. One run cannot tell flaky from genuinely failing — re-run the file 10x with a different tool if you suspect flakes.
- Non-pytest test files (raw
unittest,nose,doctest-only modules). The script depends on pytest's--report-log, which has no equivalent in those runners. pytest can collectunittest.TestCasesubclasses, so unittest-style tests inside a pytest-discoverable file are fine; standaloneunittestmains are not.
04 同仓库更多 Skills
release
Run the whole local release pipeline in order, stopping at each human gate. Triggers on "run the release", "prepare a release", "/release", "зроби реліз", "підготуй реліз". Drives the four stages back to back — bump-version → curate-changelog → release-notes → check-docs-drift — pausing after each so the human reviews the diff before the next stage. Prepares everything in the working tree; never tags, commits, or pushes. The tag push (which fires CI) stays the human's action.
release-notes
Draft partner-facing release notes from the same commits as the changelog. Triggers on "draft release notes", "release notes for the next version", "/release-notes", "нотатки релізу", "release notes партнеру". Same input as curate-changelog, different audience and tone: a short, benefit-first narrative for a user or partner — "what's new for you" — not a categorized engineer's list. Keeps only changes a user actually notices; drops internal refactors and tooling. Prints the notes to the chat to seed a GitHub Release description or a partner announcement. Writes no file.
curate-changelog
Curate the [Unreleased] section of docs/CHANGELOG.md from git history. Triggers on "curate the changelog", "update the changelog", "/curate-changelog", "онови changelog", "курування журналу". Reads git log since the last tag, FILTERS out what a reader never feels (test/ci/chore/merge), GROUPS commits about one feature into one bullet, and REWRITES technical subjects into plain language under the six Keep a Changelog categories (Added/Changed/Deprecated/ Removed/Fixed/Security). The result must have FEWER lines than the raw log — that is the proof of curation, not a dump. Leaves the edit in the working tree; never commits or pushes.
codify-rule
Turn a repeated mistake into a durable, path-scoped rule in .claude/rules/. Triggers on "codify this rule", "make a rule so this doesn't happen again", "/codify-rule", "закодифікуй правило", "петля помилка-правило". Use only when the same mistake showed up TWICE (twice = a pattern, once = noise). Names the wrong shape and the right shape with one short example of each, scopes the rule to the paths that matter, and leaves the edit in the working tree so the next agent on this repo inherits the fix. Edits only .claude/rules/; never commits or pushes.
check-docs-drift
Find and fix where docs/api.md fell behind the code. Triggers on "check for doc drift", "is the API doc up to date", "/check-docs-drift", "перевір дрейф документації", "docs drift". Runs the deterministic scripts/check-docs-drift.py (parses the public NoteBook methods with ast, compares to what docs/api.md documents — NO LLM finds the gap), reports the drift, and PROPOSES the doc edit that closes it. The gap is found by parsing; the agent writes the missing documentation in the doc's existing style. Edits only docs/; never commits or pushes.
bump-version
Decide and apply the next semver for a release. Triggers on "bump the version", "what version is next", "/bump-version", "простав версію", "яка наступна версія". Reads the next number from the deterministic scripts/next-version.sh (NEVER guesses it), explains in plain language WHICH part moved and why (e.g. "MINOR, because a feat landed: filter notes by tag"), edits the version line in pyproject.toml, and proposes the matching `git tag vX.Y.Z`. The number is decided by a rule; the agent explains and applies — the human confirms the tag. Never pushes a tag itself.