Skip to content

fix: perch coverage no longer imports lazy modules while finding mutated code - #443

Merged
jbrown9513 merged 3 commits into
mainfrom
claude/pytest-lazy-modules
Oct 30, 2026
Merged

jbrown9513 merged 3 commits into
mainfrom
claude/pytest-lazy-modules

Conversation

@jbrown9513

Copy link
Copy Markdown
Contributor

perch coverage on Python runs a pytest plugin, the mutant server, that finds the functions a mutant replaces. It asked every object in memory for __code__, and every module in sys.modules for __file__. A lazy module (one with a PEP 562 __getattr__) or a lazy proxy object imports what it stands for when asked for a name it lacks. On PrefectHQ/prefect at acc006a, in an image without Tk, that import raised ImportError: libtk8.6.so and the server stopped with exit 3.

The server now reads __code__ only from objects whose type is a function, and reads __file__ from a module's own __dict__. Neither lookup runs any code the project defines.

A new test in test/runners.test.js starts the real server on a project whose conftest.py puts a lazy module in sys.modules and a lazy object in memory, both raising ImportError. Before the first change the server stopped; with only the first change every mutant came back invalid. With both, the mutant runs and its test fails.

npm run check passes, with pytest installed. perch scan --since origin/main reports nothing.

@perchcode-bot

perchcode-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Perch Scan: no issues in 1 method at ea60f82.

See the scan

@jbrown9513
jbrown9513 merged commit 1f537e7 into main Oct 30, 2026
8 checks passed
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