Skip to content

Fix the coverage report path for a module outside the root - #14

Open
poliakarmai wants to merge 1 commit into
unclebob:masterfrom
poliakarmai:fix/coverage-report-outside-root
Open

poliakarmai wants to merge 1 commit into
unclebob:masterfrom
poliakarmai:fix/coverage-report-outside-root

Conversation

@poliakarmai

Copy link
Copy Markdown

crapper /path/to/repo run from another directory works with --no-coverage, and dies in coverage mode:

$ crapper /tmp/ubtest
  File ".../crapper/runners.py", line 286, in _coverage_report
    slug = module.relative_to(root).as_posix().replace("/", "__")
ValueError: '/tmp/ubtest' is not in the subpath of '/home/openclaw/.hermes/cache/scratch'
OR one path is relative and the other is absolute.

The README documents passing a tree by path, so a traceback is not the answer here.
The slug is only the directory name of that module's lcov file, so an absolute path
serves as well. analyze.py already falls back to the absolute path for the same
situation; this uses the same fallback.

Proof. Before the change, crapper /tmp/ubtest from an unrelated directory raised
the ValueError above. After it:

Function                       Namespace                             CC    Cov%     CRAP
f                              .tmp.ubtest.pkg.m                      1 100.0%      1.0

exit 0. Added test_coverage_report_accepts_a_module_outside_the_root next to the
existing nested-module case. pytest -q: 144 passed; the 3 failures need babashka
and uml-viewer and fail the same way without this change.

A run such as `crapper /path/to/repo` from another directory still
analyses and prints the complexity table, then dies in coverage mode with
a raw ValueError from `module.relative_to(root)`. The README documents
passing a tree by path, so the traceback is not an acceptable answer.

The fallback is the one analyze.py already uses for the same case: keep
the absolute path when the module is not under the root. The slug is only
a directory name for the lcov file, so any stable unique name works.

Proved by running `crapper /tmp/ubtest` from an unrelated directory
before (ValueError) and after (f, CC 1, 100%, CRAP 1.0, exit 0), plus
test_coverage_report_accepts_a_module_outside_the_root. Suite: 144
passed, the 3 remaining failures need babashka and uml-viewer.
@poliakarmai
poliakarmai force-pushed the fix/coverage-report-outside-root branch from c9cecb6 to d57ed65 Compare October 28, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant