Skip to content

fix: improve TestSuiteGate relevance matching for package imports #192

@omsherikar

Description

@omsherikar

Problem

_find_relevant_tests matches tests to the changed file using module_name = file_path.stem and _imports_module compares that stem to import / from targets.

This misses common cases:

  • Tests use from mypkg.submodule import foo while the file under edit is mypkg/submodule/foo.py (stem foo vs module path mypkg.submodule).
  • Package-relative imports (from . import x) are not attributed to the filesystem module under verification.

When no tests match, the gate passes with high confidence and details["note"] = "No tests cover this module", which can be a false negative for safety.

Impact

Autofix may ship changes that have tests in the repo but the gate never runs them.

Suggested direction

  • Map file_path to one or more qualified module names using project_root (same as resolving project root elsewhere).
  • Match test imports against those qualified names, not only stem.
  • Add fixtures + tests for package layout.

References

  • refactron/verification/checks/test_gate.py (_find_relevant_tests, _imports_module)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requesttesting

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions