Skip to content

Exception from the test run in a forked worker (wrongly) reports the mutant as killed #601

Open

Description

@zyv

In my project, a pytest session sometimes raises at session finish (a race in pytest's temp dir cleanup), and mutmut (wrongly) reports those mutants as killed.

With the default process_isolation = "fork", ForkRunner.submit does not catch the exceptions from run_tests in the worker, so the worker unwinds through mutmut's main loop and exits 1, which reads as killed. The fork server catches the same exception and exits with -1, which status_by_exit_code reads (as 255) as timeout. I would expect a separate status, for example, suspicious, from both runners, because the tests did not actually finish cleanly.

I have just submitted a PR to pytest to that effect (pytest-dev/pytest#15174), but I think this should be fixed in mutmut nevertheless, even if the pytest PR removes the immediate cause of the flaky misattributions that I've been hitting.

At the moment, I'm running mutmut under my own wrapper to fix this, and two other issues that I have: #387 and #600 (cool number).

Shall I submit a PR for this one?

Reproducer

mutmut 3.8.0, mutmut run, then mutmut results --all true: calc.x_add__mutmut_1: killed. Without conftest.py: survived.

src/calc.py:

def add(a, b):
    return a + b

tests/test_calc.py:

from calc import add


def test_add():
    assert add(0, 0) == 0

tests/conftest.py:

import os


def pytest_sessionfinish(session):
    if "__mutmut_" in os.environ.get("MUTANT_UNDER_TEST", ""):
        raise RuntimeError("cleanup failed")

pyproject.toml:

[tool.mutmut]
source_paths = ["src"]

[tool.pytest.ini_options]
pythonpath = ["src"]

Activity

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