Skip to content

Avoid triggering module-level __getattr__ during mutation analysis - #152

Merged
LuKrO2011 merged 1 commit into
se2p:mainfrom
Esmail-ibraheem:fix/mutation-analysis-module-getattr
Oct 24, 2026
Merged

LuKrO2011 merged 1 commit into
se2p:mainfrom
Esmail-ibraheem:fix/mutation-analysis-module-getattr

Conversation

@Esmail-ibraheem

Copy link
Copy Markdown
Contributor

Mutation analysis called hasattr() on the module under test when creating the mutation controller (inspect.getsource -> hasattr(module, "wrapped")) and when creating each mutant (hasattr(original_module, "path")). For a module with a module-level getattr (PEP 562), e.g., calendar on Python 3.12+, this ran the instrumented getattr outside of a test execution. The tracer raised TracingAbortedException, the worker died, and after a full search the restarted worker had no time left, so no tests were written.

Create the mutation controller with the tracer temporarily disabled and read the package-context attributes from the module's namespace instead.

Mutation analysis called hasattr() on the module under test when creating
the mutation controller (inspect.getsource -> hasattr(module, "__wrapped__"))
and when creating each mutant (hasattr(original_module, "__path__")). For a
module with a module-level __getattr__ (PEP 562), e.g., calendar on Python
3.12+, this ran the instrumented __getattr__ outside of a test execution.
The tracer raised TracingAbortedException, the worker died, and after a full
search the restarted worker had no time left, so no tests were written.

Create the mutation controller with the tracer temporarily disabled and read
the package-context attributes from the module's namespace instead.
@LuKrO2011

Copy link
Copy Markdown
Member

Hi,
thank you @Esmail-ibraheem for reporting the issue and proposing the fix.
I think the worker still dies when a module with __getattr__ deletes a top-level subclass, and when a base class’s metaclass defines __getattr__. The metaclass case also crashes before the search, in _check_sut_uses_random.
I am currently working on extending your solution regarding that and then I will merge this.

@Esmail-ibraheem

Copy link
Copy Markdown
Contributor Author

ok, sure, if you need any help, just comment

@LuKrO2011
LuKrO2011 merged commit 91f40b2 into se2p:main Oct 24, 2026
1 check 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.

2 participants