fix: support src-layout Python projects in test_coverage detector#489
Closed
AreboursTLS wants to merge 1 commit intopeteromallet:mainfrom
Closed
fix: support src-layout Python projects in test_coverage detector#489AreboursTLS wants to merge 1 commit intopeteromallet:mainfrom
AreboursTLS wants to merge 1 commit intopeteromallet:mainfrom
Conversation
resolve_import_spec now tries src/-prefixed candidates when direct module-path candidates don't match any production file. This handles the common src-layout pattern (e.g. src/argos_toolkit/foo.py). _build_prod_by_module now strips the 'src/' prefix from relative paths before computing module names, so the module index maps 'argos_toolkit.foo' instead of 'src.argos_toolkit.foo'.
eebf9df to
30a686e
Compare
Owner
|
Thanks for the fix, @AreboursTLS! The src-layout gap is real — PEP 621 projects with Cherry-picked both changes into
One minor adjustment: moved All tests pass. Thanks for the clean, targeted fix! |
peteromallet
added a commit
that referenced
this pull request
Mar 21, 2026
resolve_import_spec now tries src/-prefixed candidates when direct match fails, and _build_prod_by_module strips the src/ prefix from relative paths before computing module names. Both changes are needed so that src-layout projects (PEP 621) correctly map tests to production files. Adjustments: moved _SRC_PREFIXES to module-level constant (was function-local) Cherry-picked from PR #489 by @AreboursTLS Co-Authored-By: AreboursTLS <AreboursTLS@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
stuckvgn
pushed a commit
to Open-Paws/desloppify
that referenced
this pull request
Mar 21, 2026
resolve_import_spec now tries src/-prefixed candidates when direct match fails, and _build_prod_by_module strips the src/ prefix from relative paths before computing module names. Both changes are needed so that src-layout projects (PEP 621) correctly map tests to production files. Adjustments: moved _SRC_PREFIXES to module-level constant (was function-local) Cherry-picked from PR peteromallet#489 by @AreboursTLS Co-Authored-By: AreboursTLS <AreboursTLS@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In Python projects using
src/layout (where production code lives undersrc/package_name/), the test_coverage detector fails to link test files to source files.resolve_import_specconverts import specs likemypackage.footomypackage/foo.py, but production files are stored assrc/mypackage/foo.py. The candidates never match._build_prod_by_modulecreates module aliases with asrc.prefix (e.g.src.mypackage.foo) that import specs from tests never include.This causes all modules in src-layout projects to be flagged as
untested_criticaleven when comprehensive test suites exist that import them.Fix
resolve_import_spec(languages/python/test_coverage.py): After checking direct candidates againstproduction_files, also trysrc/-prefixed candidates._build_prod_by_module(engine/detectors/coverage/mapping_analysis.py): Stripsrc/prefix from relative paths before computing module names, so the index mapsargos_toolkit.fooinstead ofsrc.argos_toolkit.foo.Testing