fix: support non-editable installs (site-packages import precedence)#487
Open
pythoniste wants to merge 1 commit intoboxed:mainfrom
Open
fix: support non-editable installs (site-packages import precedence)#487pythoniste wants to merge 1 commit intoboxed:mainfrom
pythoniste wants to merge 1 commit intoboxed:mainfrom
Conversation
When the package-under-test is installed in site-packages as a non-editable wheel rather than via `pip install -e .`, mutmut's trampoline-injected code in the mutants/ directory was never loaded. Python imported the original (non-mutated) modules from site-packages because they were already cached in sys.modules. The stats phase found zero test coverage and all mutants were marked "not checked". Add _patch_imported_packages() to setup_source_paths(): after adding mutants/ to sys.path, patch __path__ on every already-imported package so submodule lookups prefer the mutants tree. Flush leaf modules whose mutated .py exists on disk so they get re-imported with trampoline code. Add _copy_parent_init_files() to copy_src_dir(): when paths_to_mutate targets individual files, parent __init__.py files were missing from the mutants tree, preventing Python from recognising it as a package. Tested on a Pydantic-heavy project (8,996 mutants): stats phase now finds 477 covered functions and achieves a 70% kill rate, where previously it found zero coverage.
Author
|
By the way, the branch name is misleading. At first, I wanted to fix Pydantic and then, I fixed something else. |
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.
When the package-under-test is installed in site-packages as a
non-editable wheel rather than via
pip install -e ., mutmut'strampoline-injected code in the mutants/ directory was never loaded.
Python imported the original (non-mutated) modules from site-packages
because they were already cached in sys.modules. The stats phase found
zero test coverage and all mutants were marked "not checked".
Add _patch_imported_packages() to setup_source_paths(): after adding
mutants/ to sys.path, patch path on every already-imported package
so submodule lookups prefer the mutants tree. Flush leaf modules whose
mutated .py exists on disk so they get re-imported with trampoline code.
Add _copy_parent_init_files() to copy_src_dir(): when paths_to_mutate
targets individual files, parent init.py files were missing from
the mutants tree, preventing Python from recognising it as a package.
Tested on a Pydantic-heavy project (8,996 mutants): stats phase now
finds 477 covered functions and achieves a 70% kill rate, where
previously it found zero coverage.