Skip to content

Run natively on Windows - #1

Merged
kimvais merged 3 commits into
mainfrom
windows-port
Nov 18, 2026
Merged

kimvais merged 3 commits into
mainfrom
windows-port

Conversation

@kimvais

@kimvais kimvais commented Nov 18, 2026

Copy link
Copy Markdown
Owner

mutmut refuses to start on Windows and points at WSL (boxed#397). This makes it run natively.

Approach

A third MutantRunner, SpawnRunner, next to the fork and forkserver ones. It starts a fresh Python process per mutant (mutmut.workers.spawn_worker), hands it the mutant and its tests on stdin and reads the verdict from the exit code. One mutant per process, same as fork, so the verdicts are the same. A replacement worker is started as soon as a result comes in, so the pytest import is paid while it waits.

process_isolation = "spawn" is the default on Windows. fork / forkserver in the config fall back to it with a warning there, so a pyproject.toml shared with POSIX users keeps working. On POSIX nothing changes unless spawn is asked for.

Mutant generation and coverage gathering relied on forked children inheriting state() and sys.path ... under the spawn start method they are handed what they need.

Result

The whole test suite passes on Windows 11, Python 3.10, including the e2e projects with the same snapshots as on Linux. One difference: the my_lib segfault mutant is killed by a failing test, because ctypes turns the access violation into an OSError on Windows.

my_lib (111 mutants) runs at about 5 mutations/second here.

Outside the package

CI runs the test matrix on windows-latest too, which doubles the test jobs. README and ARCHITECTURE no longer say POSIX only.

Left out

  • CPU-time limit. There is no RLIMIT_CPU, so a runaway mutant is stopped by wall clock only, and child processes it started are not killed with it.
  • Reusing a worker for several mutants (the approach in Windows support boxed/mutmut#404). Faster, but that PR reports verdicts that differ from main.
  • HISTORY.rst entry, there is no unreleased section to put it in.
  • The two pyrefly e2e tests fail when the checkout lives under a dot-directory (a .wt worktree here), pyrefly skips the files. Not Windows related, the same project passes elsewhere.

Windows has no os.fork, so neither existing runner can work there.
SpawnRunner starts a fresh Python process per mutant, hands it the
mutant and its tests on stdin and reads the verdict from the exit code.
It is the default on Windows; a config asking for fork or forkserver
falls back to it with a warning, so a pyproject.toml shared with POSIX
users keeps working.

Timeouts are wall-clock only, as there is no RLIMIT_CPU. A worker that
fails outside the tests exits 35 (suspicious) instead of Python's 1,
which would count as a kill.
Remove the exit that sent Windows users to WSL. Mutant generation and
coverage gathering relied on forked children inheriting state() and
sys.path; under the spawn start method they are handed what they need.

The my_lib segfault mutant is killed by a failing test on Windows,
because ctypes turns the access violation into an OSError there.

Refs boxed#397.
The default encoding there is the ANSI code page, which cannot encode
the "ǁ" in mutant names, the spinner or the emoji. It went unnoticed
locally because this machine runs with a UTF-8 code page; the Windows
CI runner added in 92e1540 does not.
@kimvais
kimvais merged commit fbc0f79 into main Nov 18, 2026
26 checks 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.

1 participant