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.

How to diagnose

  1. 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 your coverage.json, not in your source code.

  2. Confirm coverage.json was generated. Run pytest --cov=<your_src_dir> --cov-report=json and 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.

  3. Check for a 'files' key mismatch. If you see the 'files' key missing error, your coverage.json was generated by a coverage.py version that uses a different schema. Upgrade or pin coverage to a version compatible with pytest-cov 4.x and regenerate the file.

  4. Isolate an empty prioritization result. If smart-test produces no modules to test, check the min_threshold in prioritize_modules() (default 50.0). All your modules may already be above 50% coverage. Lower the threshold or target a specific module path directly.

  5. 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 what FunctionSignature and ClassSignature objects it produces. Missing raises, empty params, or complexity=1 on a clearly complex function indicate the analyzer couldn't parse that construct.

Source files

Tags: tests, coverage, generation