Smart Test errors
Common error signatures
Most smart-test failures fall into two categories: coverage file problems and malformed source code that the AST analyzer cannot parse.
| Exception | Message pattern | Likely cause |
|---|---|---|
FileNotFoundError |
Coverage file not found: {path} |
parse_coverage_json() was called before pytest --cov produced a coverage.json, or the path passed to it is wrong |
ValueError |
Invalid coverage JSON at {path}: {detail} |
The coverage.json file exists but is not valid JSON — typically a truncated or partially written file |
ValueError |
Unexpected coverage JSON structure in {path}: 'files' key missing or not a dict |
The JSON is valid but doesn't match the expected pytest-cov schema — usually caused by a coverage.py version mismatch |
Where errors originate
Failures in the coverage-parsing stage happen in parse_coverage_json() before any test generation begins. Failures in the generation stage come from ASTFunctionAnalyzer, generate_test_for_function(), or generate_test_for_class() when the source module has syntax the analyzer doesn't handle.
parse_coverage_json(json_path)— reads and validatescoverage.json; raisesFileNotFoundErrororValueError(see above)prioritize_modules(modules, min_threshold)— filters by coverage threshold; a completely empty result here means every module is abovemin_threshold(default50.0), not that parsing failedgroup_into_batches(modules, max_batches)— groups by package path; an empty batch list meansprioritize_modules()returned nothinggenerate_test_for_function(module, func)— depends onASTFunctionAnalyzer.analyze()having run first; iffuncis missing expected keys the output will be an empty or broken test stubTestAuditWorkflow.execute()andTestGenerationWorkflow.execute()— orchestrate the subagents; errors from the functions above bubble up through these
How to diagnose
-
Identify which stage failed. Coverage-parsing errors (
FileNotFoundError,ValueError) happen before any test generation. If you see one of the message patterns in the table above, the problem is in yourcoverage.json, not in your source code. -
Confirm
coverage.jsonwas generated. Runpytest --cov=<your_src_dir> --cov-report=jsonand verify the file exists at the path you're passing to smart-test. If the file is missing, pytest-cov either wasn't installed or the run failed before producing output. -
Check for a
'files'key mismatch. If you see the'files' key missingerror, yourcoverage.jsonwas generated by a coverage.py version that uses a different schema. Upgrade or pincoverageto a version compatible with pytest-cov 4.x and regenerate the file. -
Isolate an empty prioritization result. If smart-test produces no modules to test, check the
min_thresholdinprioritize_modules()(default50.0). All your modules may already be above 50% coverage. Lower the threshold or target a specific module path directly. -
Debug AST analysis failures. If test generation produces empty or malformed stubs, run
ASTFunctionAnalyzer().analyze(source_code, file_path)directly on the failing module to see whatFunctionSignatureandClassSignatureobjects it produces. Missingraises, emptyparams, orcomplexity=1on a clearly complex function indicate the analyzer couldn't parse that construct.
Source files
src/attune/workflows/test_audit/coverage_parser.pysrc/attune/workflows/test_gen/src/attune/workflows/test_gen_parallel.py
Tags: tests, coverage, generation