Enums with custom __init__ cannot be imported under mutmut: KeyError: '_mutmut_orig' #600
Copy link
Copy link
Open
Description
My project has enums with a custom __init__, and mutmut run stops at the stats run because the mutated module cannot be imported.
Enum calls __init__ once per member while the class is still being created, before the trampoline table of its methods is assigned after the class body. __new__ is already in NEVER_MUTATE_FUNCTION_NAMES for that reason.
Skipping __init__ and _generate_next_value_ on an enum class the same way works for me. Shall I submit a PR?
Reproducer
mutmut 3.8.0, pytest 9.1.1, Python 3.15, mutmut run:
File ".../mutmut/mutation/trampoline.py", line 75, in trampoline
orig_func = mutants_dict["_mutmut_orig"]
KeyError: '_mutmut_orig'
ERROR tests/test_color.py - KeyError: '_mutmut_orig'
failed to collect stats. runner returned 2
src/color.py:
from enum import Enum
class Color(Enum):
RED = 1
def __init__(self, value):
self.label = f"c{value}"tests/test_color.py:
from color import Color
def test_label():
assert Color.RED.label == "c1"pyproject.toml:
[tool.mutmut]
source_paths = ["src"]
[tool.pytest.ini_options]
pythonpath = ["src"]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
boxed commentedon Oct 16, 2026
That sounds like a clean win yea.
zyv commentedon Oct 16, 2026
@boxed alright, thanks for getting back to me! I've just submitted #603. Hope that helps.