Fast pytest-compatible test runner with a native Zig supervisor
pip install ztest-runner Copy PIP instructions
Process-supervised Python test runner in Zig: pidfd/killpg containment, a Zygote worker pool, 2.6× lower memory than pytest-xdist, --llm JSONL for AI agents.
pip install ztest-runner # PyPI wheel, no toolchain uvx --from ztest-runner ztest --version # zero-install, one command curl -LsSf https://raw.githubusercontent.com/alexchen-sys/ztest/main/scripts/install.sh | sh curl -LsSf https://raw.githubusercontent.com/alexchen-sys/ztest/main/scripts/install.sh | sh -s -- --system Prebuilt static musl binaries (stripped, x86_64 and aarch64) sit on GitHub Releases if you would rather not pipe a shell script; the installer verifies SHA256SUMS and honors ZTEST_VERSION / ZTEST_INSTALL_DIR. ztest --version prints ztest 0.5.1 (Zig 0.17.0). Building from source needs Zig 0.17.0 and is covered at the end of this file.
pytest starts in 600–900 ms and hands an agent 5,000–25,000 tokens of banners, progress bars, PASSED lines and multi-page tracebacks. ztest --llm starts in ~1 ms, prints nothing for a passing test, and emits one JSON line per failure plus a final summary — measured 85.7 % fewer bytes than pytest -v on a 42-test probe, and the gap widens as tracebacks deepen. A test that hangs inside a C extension holding the GIL cannot take the agent's session with it: the kernel kills the process group, not a Python-level timer. Numbers and method: BENCHMARKS.md §1.
pytest-timeout's signal method cannot interrupt a C extension that holds the GIL: the handler runs when the call returns, which is how a 1 s deadline became a 17.6 s wait, and how a call that never returns turns a one-minute CI step into a sixty-minute job. Its thread method uses os._exit, which leaves every child the test created alive and holding the job's pipes. ztest pins worker identity with pidfd_open, holds the zombie with waitid(WNOWAIT), kills with kill(-pgid, SIGKILL), sweeps setsid escapees under a child subreaper, and runs a native watchdog over a MAP_SHARED process-group registry — a hung worker dies on schedule and leaves zero processes behind (measured: 1.28 s, 0 leaked processes). Rationale and accepted limits: ADR-004.
pytest -n4 re-collects the suite in every worker over execnet, errors out whenever collection order differs between workers, and pays a full interpreter plus import graph per worker. In a nine-suite cross-check it failed on 3 of 9 (33 %) and peaked at 1.70×–4.94× (median 2.60×) the memory of ztest -j4 — 1.38 GiB against 462 MiB on dateparser. ztest forks workers from one pre-warmed zygote, schedules by file with LPT, recycles workers per file, and holds a flat memory ceiling on suites where a monolithic pytest is OOM-killed.
ztest runs pytest suites under kernel-level process-group and pidfd containment. It keeps the Python test surface — conftest.py, fixtures, markers, pytest.raises, unittest.TestCase — and moves supervision, parallelism, and timeout enforcement into a native Zig supervisor.
Every worker runs in its own process group under PR_SET_PDEATHSIG, pidfd-pinned identity, waitid(WNOWAIT) zombie pinning, and a subreaper sweep. The supervisor starts in ~1.2 ms (--version) without booting a master Python interpreter or pluggy plugin chain, and workers fork from a pre-warmed Python zygote to amortize interpreter startup across files.
For CI and automation, --llm emits JSON Lines: one object per failure event and a stable summary record at the end.
The compatibility shim is compiled into the binary. No Python package or pytest installation is required at runtime: the shim registers the pytest and _pytest modules directly.
Prebuilt binaries and PyPI wheels are the normal path (see Install in 1 second). Contributors build from a checkout:
git clone https://github.com/alexchen-sys/ztest cd ztest zig build -Doptimize=ReleaseSafe The binary lands at zig-out/bin/ztest. Installing it is optional:
sudo install -m 0755 zig-out/bin/ztest /usr/local/bin/ztest ReleaseSafe keeps the overflow and bounds checks that matter for a program whose job is killing process trees. Debug builds are fine for development; ReleaseFast gains little here because run time is dominated by the tests, not by the supervisor.
Run the example suite shipped in this repository:
ztest examples/ The summary line reads 8 passed. Point ztest at a directory or a set of files:
ztest examples/ ztest examples/test_calc.py examples/test_text.py With no arguments, ztest runs the default target tests/:
ztest Eight workers, and a 30 second ceiling on any single test:
ztest -j8 --timeout=30 tests/ Filter by name or by marker, using pytest expression syntax:
ztest -k "login or logout and not slow" tests/ ztest -m "integration" tests/ List what would run, without running it:
ztest --collect-only tests/ Machine-readable output for agents and CI:
ztest --llm --timeout=60 tests/ Stop early, first failure or after N failures:
For command-line compatibility, the parser accepts pytest display-formatting flags (--tb=..., --tb , --color=..., -ra, -rf, -rA) as no-ops. Unimplemented semantic flags (-W, -o, -p, -c, --import-mode, --rootdir, --strict-markers, --disable-warnings) are rejected with exit code 4 rather than silently ignored.
Not supported in the default native engine (use --engine=pytest when required):
zig build test This runs the native suite: 48 tests (43 in src/main.zig, 3 in src/cli.zig, 2 in src/spawn_arm.zig). The suite covers framing and CRC rejection, IPC peer authentication, the containment watchdog and its registry, orphan-sweep exclusions, CLI parsing and its bounds, interpreter resolution, exit-code parity, and an anti-drift test that compiles the embedded shim under python3 so the binary cannot ship a shim that does not parse.
The behavioral gate lives in tests/: 132 unittest cases that run the real binary against 120 fixture trees, each reproducing a compatibility bug confirmed against an OSS suite (see BENCHMARKS.md). It needs the built binary and skips cleanly without one:
ZTEST_BIN=zig-out/bin/ztest python3 -m pytest tests/test_oss_regressions.py -q The binary under test is $ZTEST_BIN when set, else this repo's zig-out build, else the first ztest on PATH.
ztest --version prints the version: ztest 0.5.1 (Zig 0.17.0).
Full matrix, method, and the containment probes: BENCHMARKS.md. Over 100 real PyPI suites on 4 vCPU / 8 GiB: wall median 1.465× faster than serial pytest across the 90 full-parity suites, 90/96 (93.8 %) FULL-PARITY on the native engine and 94/96 (97.9 %) with --engine=pytest; against pytest -n4 (xdist), ztest -j4 uses 1.70×–4.94× less peak memory (median 2.60×) and passes the 3 of 9 suites where xdist fails. Every number is reproducible from the manifest and the harness in benchmarks/.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




