Repository navigation
Conversation
…cts no tests The forced fail control only rejected exit code 0, so a pytest INTERNALERROR (3) or a run without collected tests (5) was accepted as a successful control and mutation testing continued. Both now abort the run. Exit codes 1 (tests failed) and 2 (collection interrupted by the forced fail) are still accepted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The forced-failure control (
run_forced_fail_test) now aborts the run, with a clear message and exit status 1, when pytest exits with code 3 (internal error) or 5 (no tests collected). Codes 1 (tests failed) and 2 (collection interrupted by the forced fail) are still accepted, so a genuine forced failure proceeds as before.Closes #647
Root cause
run_forced_fail_test()insrc/mutmut/__main__.pyonly rejected a runner result of0. A pytestINTERNALERROR(exit code 3, e.g. aconftest.pyhook raising duringpytest_sessionstart) was therefore treated as a successful control: mutmut went on to "Running mutation testing" and exited 0, even though no test had run and the control could not be verified. The same holds for exit code 5 (no tests collected).Fix
After the forced fail run, exit code 0 keeps its existing message. Exit codes 3 and 5 dump the captured output, print
FAILED: Forced fail test could not run the tests (exit code N)and exit with status 1.Exit code 2 is deliberately still accepted: with the forced fail enabled, a test module that calls mutated code while it is imported (for example
@pytest.mark.parametrize("x", cases())) fails collection, and pytest reports that as code 2. Withprocess_isolation = "forkserver"this is a normal outcome of the control, because the parent does not import the test modules beforehand.For a mutant, exit code 3 already counts as killed (
stats.py); in the control it means that no test ran, so detectability was never checked.Known limitation, out of scope here: exit code 4 aborts the run only in
forkmode. Inforkservermoderun_in_forkturns theBadTestExecutionCommandsExceptionraised in the child into exit code 1, which the control accepts.How I verified it
mainthe two abort tests fail (DID NOT RAISE SystemExit) and the code 2 test passes; with the change all pass.uv run pytest tests/mutation/test_mutation.py -k forced_fail-> 2 failed, 4 passed before; 6 passed afterMUTANT_UNDER_TEST == "fail"): onmain,mutmut runproceeds to mutation testing and exits 0; with the change it printsFAILED: ... (exit code 3)and exits 1.process_isolation = "forkserver"with a test using@pytest.mark.parametrize("x", cases())wherecases()is project code: exits 0 and runs the mutants onmainand with the change.uv run pytest-> 482 passed, 4 skippeduv run pre-commit run --all-files(ruff, ruff-format, mypy) -> all passedThis PR was prepared with AI assistance (Claude Code). I have reviewed the change and the test results.