用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill test-coverage-review命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | test-coverage-review |
| description | > Use when this capability is needed. |
This skill audits test coverage in Python projects, identifies gaps, writes new tests, and verifies that the test suite passes — all following pytest best practices.
Read the best-practices reference file to ground your work:
cat references/best-practices.md
Use the practices and source citations in that file as your authoritative checklist.
Determine the mode from the user's request.
Use when the user says "review my tests", "check my coverage", or "are my tests good enough".
Step 1: Discover the project structure
Identify:
src/ layout)tests/, test/, or co-located)conftest.py files and shared fixturespyproject.toml, setup.cfg, or .coveragercStep 2: Map source modules to test files
For every public module in the package, check whether a corresponding test file exists. Flag modules with no test file at all.
| Source module | Test file | Status |
|---|---|---|
mypackage/api.py | tests/test_api.py | ✅ exists |
mypackage/parser.py | — | ❌ missing |
Step 3: Audit test quality
For each existing test file, check against the reference checklist:
test_<module>.py, classes prefixed Test,
methods prefixed test_.@pytest.fixture, not setUp() or
duplicated code.Step 4: Run coverage (if possible)
pytest tests/ --cov=<package> --cov-report=term-missing --tb=short -q
Report:
Step 5: Produce the audit report
Output a markdown table of findings:
| File | Issue | Severity | Source |
|---|---|---|---|
tests/test_api.py | No tests for error paths in fetch() | critical | [PYTEST-GOOD] |
tests/test_parser.py | _parse() mocked instead of tested directly | warning | [MOCK-BOUND] |
| — | No test file for mypackage/utils.py | critical | [COVERAGE] |
Severity levels:
Use when the user says "write tests for this", "add tests for this module", or has just finished a feature.
Step 1: Analyze the code under test
Read the module and identify:
Step 2: Plan test categories
For each public class or function, plan tests in these categories:
| Category | What to test |
|---|---|
| Happy path | Normal inputs produce expected outputs |
| Edge cases | Empty inputs, None, zero, boundary values |
| Error handling | Invalid inputs raise expected exceptions |
| Return types | Return values have correct types and structure |
| Side effects | External calls are made with correct arguments |
| State changes | Object state changes correctly after method calls |
Present the plan to the user before writing.
Step 3: Write the test file
Follow this structure:
"""Tests for <module description>."""
from unittest.mock import patch, MagicMock
import pytest
from <package>.<module> import <Class>, <function>
# ---------------------------------------------------------------------------
# Sample data
# ---------------------------------------------------------------------------
SAMPLE_DATA = ... # Module-level test data constants
# ---------------------------------------------------------------------------
# <ClassName> tests
# ---------------------------------------------------------------------------
class Test<ClassName>:
"""Tests for the <ClassName> <type>."""
def test_<behavior>(self):
"""Verify <what is being tested>."""
# Arrange
...
# Act
...
# Assert
...
Rules:
test_<module>.pyclass Test<Name>: with class docstrings"""Verify <what>."""# ---) between test classes@pytest.fixture, not setUp()Step 4: Mock at the boundary
Mock external dependencies only:
requests.get / requests.post for HTTP callsopen / pathlib.Path for file I/Otime.sleep, datetime.now when testing time-dependent logicDo NOT mock:
# CORRECT — mock the HTTP boundary
@patch("mypackage.api.requests.get")
def test_fetch_sends_timeout(self, mock_get):
mock_get.return_value = MagicMock(status_code=200, json=lambda: {})
client = APIClient()
client.fetch("https://example.com")
_, kwargs = mock_get.call_args
assert kwargs["timeout"] == 10
# WRONG — don't mock internal methods
@patch.object(Parser, "_transform") # ← test this directly instead
def test_parse(self, mock_transform):
...
Step 5: Run and verify
After writing tests:
# Run the new tests
pytest tests/test_<module>.py -v --tb=short
# Run the full suite to check for regressions
pytest tests/ --tb=short -q
# Check coverage of the new module
pytest tests/ --cov=<package>.<module> --cov-report=term-missing
Report the test count and pass/fail status. Note the count for the changelog entry:
- **tests/test_<module>.py**: N unit tests for <description>.
Use when the user says "improve my coverage", "fill the gaps", or coverage reports show low percentages.
Step 1: Identify uncovered code
Run coverage and parse the Missing column to identify:
Step 2: Prioritize by risk
Write tests for gaps in this order:
except blocks, validation failuresif/else pathsStep 3: Write gap-filling tests
Add tests to existing test files (don't create new files if a test file already exists for that module). Follow the same structure and conventions as the existing tests.
Step 4: Re-run coverage and report
Show before/after coverage numbers for the affected modules.
TestCase, self.assertEqual) into
a pytest-native project.Source: areed1192/finance-news-aggregator — distributed by TomeVault.