Skip to content

Enums with custom __init__ cannot be imported under mutmut: KeyError: '_mutmut_orig' #600

Open

Description

@zyv

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"]

Activity

  1. boxed commented on Oct 16, 2026

    @boxed
    Owner

    That sounds like a clean win yea.

  2. zyv commented on Oct 16, 2026

    @zyv
    Author

    @boxed alright, thanks for getting back to me! I've just submitted #603. Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions