ワンクリックで
test-coverage-expansion
A systematic workflow to analyze, expand, and enforce robust test coverage across any Python project.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
A systematic workflow to analyze, expand, and enforce robust test coverage across any Python project.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | test-coverage-expansion |
| description | A systematic workflow to analyze, expand, and enforce robust test coverage across any Python project. |
This skill provides a structured methodology for expanding test coverage systematically, uncovering hidden edge cases, and ensuring that tests add real value rather than just ticking boxes.
Before writing any tests, establish a clear baseline and identify the most critical areas lacking coverage.
pytest --cov=src --cov-report=term-missing in Python).pytest_cov_baseline.txt) so you can compare progress later.0% coverage or high complexity but low coverage (< 50%).When adding new tests to untested legacy or complex code, isolation is key.
unittest.mock.MagicMock or pytest-mock in Python) to fake API calls, databases, and file I/O.Missing Lines: Look at the exact line numbers reported as missing in the coverage report. Design specific inputs that force the code to traverse those conditional branches (if, elif, except).Do not just write happy-path tests. Actively hunt for hidden bugs.
None, NaN, Infinity.ZeroDivisionError or unhandled exception), DO NOT fix the application code. Your role is strictly QA. Mark the test as an expected failure (e.g., using @pytest.mark.xfail(strict=True) in Python), document the bug clearly in your report or PROGRESS.md, and assign the fix to the Dev team.Validate that your tests actually increased coverage without breaking the existing suite.
xfail). A coverage expansion task should not leave the CI pipeline red.Document the coverage expansion clearly for the next agent or human developer.
pytest_cov_latest.txt (or equivalent).PROGRESS.md or the project's changelog.test: expand coverage for risk module (0% -> 100%), added 25 tests.Coverage expansion has no value if it can regress silently.
--cov-fail-under=N flag to the CI coverage command. The pipeline fails if total coverage drops below N%.
pytest --cov=src --cov-fail-under=80.coveragerc to enforce stricter limits on critical modules (e.g., risk_manager.py must stay at 100%).Coverage % measures which lines run, not whether tests catch bugs. Mutation testing fills this gap.
mutmut (Python)
pip install mutmut
mutmut run --paths-to-mutate src/trading/risk_manager.py
mutmut results
For ML/trading code, manual edge cases miss the combinatorial space. Property-based tests generate hundreds of random inputs automatically.
hypothesis (Python)
pip install hypothesis
from hypothesis import given, strategies as st
@given(st.floats(min_value=0.01, max_value=10.0))
def test_kelly_sizing_never_exceeds_max_lot(risk_fraction):
result = compute_kelly_lot(risk_fraction, balance=10000)
assert result <= MAX_LOT_SIZE
st.floats() with min_value/max_value and allow_nan=False unless testing NaN handling explicitly.python -m pytest tests/ --cov=src --cov-report=term-missing -qpython -m pytest tests/ --cov=src --cov-fail-under=80 -qwith pytest.raises(ExpectedException):assert value == pytest.approx(expected_value)pytest -W error to catch deprecation and runtime warnings. Caution: this flag causes false positives on legacy codebases — apply it to new modules only, or filter specific warning categories via filterwarnings in pytest.ini.