Quickstart: Smart Test
Find untested code and generate pytest tests with edge cases.
/smart-test <path or module to test>
Result: A coverage gap report ranked by risk, plus working pytest functions with assertions for untested functions, branches, and error paths.
Prerequisites
- The project is cloned and installed locally
pytest-covhas produced acoverage.jsonfile for your project
Steps
-
Parse your coverage report. Point
parse_coverage_json()at the JSON file thatpytest-covwrote:from attune.workflows.test_audit.coverage_parser import parse_coverage_json, prioritize_modules modules = parse_coverage_json("coverage.json")You'll get a list of
ModuleCoverageobjects, each withpath,stmts,covered,missing_lines, and apctscore. -
Identify the highest-priority gaps. Filter out modules above your coverage threshold (default 50%) and sort by priority:
targets = prioritize_modules(modules) print(targets[0].path, targets[0].pct) # src/attune/help/engine.py 23.4The module with the lowest coverage and the most uncovered statements appears first.
-
Generate tests for the top module. Run the test generation workflow against that path:
attune workflow run test-gen --path src/attune/help/engine.pyExpected output:
## Summary Analyzed 12 functions. Designed 31 test cases. Wrote 1 test file. ## Test Gaps - engine.py: _resolve_template — no branch coverage on missing-key path - engine.py: render — exception handler never triggered ## Suggestions 1. Add parametrized tests for empty-input edge cases (low effort) 2. Add error-path test for FileNotFoundError in parse_coverage_json (low effort)The generated file is written to
tests/behavioral/generated/. -
Verify the tests pass.
pytest tests/behavioral/generated/ -vAll generated tests should pass on the first run against your current codebase.
Next: Run pytest --cov again and re-run prioritize_modules() to confirm coverage improved for the module you targeted.