Metadata-Version: 2.4
Name: pytest-rs
Version: 0.0.15
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Testing
License-File: LICENSE
License-File: THIRD-PARTY-NOTICES.md
Summary: A fast, drop-in compatible pytest runner written in Rust
Keywords: pytest,testing,rust,test-runner
Author: Yasu-umi
License-Expression: MIT
Requires-Python: >=3.13
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/Yasu-umi/pytest-rs
Project-URL: Source, https://github.com/Yasu-umi/pytest-rs
Project-URL: Tracker, https://github.com/Yasu-umi/pytest-rs/issues

# pytest-rs

pytest-rs is a re-implementation of the popular Python testing framework [pytest](https://github.com/pytest-dev/pytest) in Rust, focused on **speed**: a drop-in compatible runner where startup, collection, fixture orchestration, coverage measurement, and reporting are native code, while test bodies run on embedded CPython.

> Note: This project is currently in active development (alpha stage). Many features are still under implementation and subject to change. See [docs/DESIGN.md](https://github.com/Yasu-umi/pytest-rs/blob/main/docs/DESIGN.md) for the architecture and roadmap.
>
> pytest-rs is an independent project, not affiliated with or endorsed by the pytest project.

## Installation

Prebuilt wheels are published to PyPI for Linux (x86_64 / aarch64) and macOS (arm64) on CPython 3.13 / 3.14 / 3.15:

```sh
uv add --dev pytest-rs    # or: pip install pytest-rs
```

Then run your existing suite, no changes needed:

```sh
pytest-rs                       # whole suite, like `pytest`
pytest-rs tests/test_foo.py     # one file
pytest-rs -n 4                  # parallel workers (pytest-xdist compatible)
pytest-rs --cov=mypkg           # native coverage (pytest-cov compatible)
```

`pytest-rs` reads the same configuration pytest does (`pytest.ini`, `pyproject.toml` `[tool.pytest]` / `[tool.pytest.ini_options]`, `tox.ini`, `setup.cfg`) and understands the familiar flags (`-v`, `-x`, `-k`, `-m`, `--lf`, `--tb=...`, `-p no:NAME`, ...). It leaves the `pytest` command itself untouched, but it does install an importable `pytest` package, so `import pytest` (fixtures, `pytest.raises`, `pytest.mark`, `pytest.approx`, ...) works standalone too — e.g. from a subprocess that never runs through the `pytest-rs` binary.

> Don't install this alongside the real `pytest` package in the same environment: both distributions claim the same `pytest` import path, and pip/uv have no awareness that they conflict — installation order decides which files end up in `site-packages/pytest/`, and neither installer cleanly removes the other's.
>
> When switching a project over, `pytest` itself, `pluggy`, and `iniconfig` are the only packages pytest-rs supersedes — safe to drop. Any other pytest plugin the project uses (`pytest-django`, `pytest-aiohttp`, ...) is a real, separately-installed package unless it's one of the plugins listed under [Bundled plugins](#bundled-plugins) below, and must stay installed for its fixtures/hooks to keep working.
>
> Watch for `pytest` arriving *transitively*: every pytest plugin declares a dependency on it, so keeping one of the bundled plugins installed (`pytest-mock` for its `MockerFixture` annotation, say) pulls the real `pytest` back in behind your back. `uv tree --package pytest` / `pip show pytest` after a lock change is the quick check; the annotations those plugins are usually kept around for ship with pytest-rs itself (see [Type annotations](#type-annotations)).

### Adding a third-party plugin without pulling `pytest` back in

Because every plugin depends on `pytest`, the obvious `uv add --dev pytest-aiohttp` installs the real distribution on top of pytest-rs's files. Install the plugin *without its dependencies* instead — the ones pytest-rs supersedes are already in place — and add back only the dependencies it genuinely needs.

Take `pytest-aiohttp==1.1.1`. It requires `pytest`, `pytest-asyncio`, and `aiohttp`: the first two are provided by pytest-rs, the third is a real package you still need.

One-off (a CI step, or trying a plugin out):

```sh
uv pip install --no-deps pytest-aiohttp==1.1.1   # or: pip install --no-deps ...
uv pip install aiohttp                           # its non-pytest dependencies, explicitly
```

For a locked project, keep the plugin in your dependency groups and override the requirements pytest-rs supersedes with a marker that never matches — uv then resolves the plugin but installs neither `pytest` nor `pytest-asyncio`:

```toml
[dependency-groups]
dev = ["pytest-rs", "pytest-aiohttp==1.1.1"]

[tool.uv]
override-dependencies = [
    "pytest ; sys_platform == 'never'",
    "pytest-asyncio ; sys_platform == 'never'",
]
```

`uv sync` on that project installs `pytest-rs`, `pytest-aiohttp`, and `aiohttp` (plus aiohttp's own deps) — and no `pytest`. Confirm with `uv pip list | grep -i pytest`: seeing a bare `pytest` line means the real distribution got in and has overwritten part of pytest-rs's `pytest/` directory.

Which names to override is just "whichever of pytest-rs's own bundled distributions the plugin asks for": `pytest`, `pluggy`, `iniconfig`, plus any of the [bundled plugins](#bundled-plugins) — e.g. a plugin depending on `pytest-asyncio` (`pytest-aiohttp`) or on `pytest-xdist` (`pytest-split`-style plugins) needs that name overridden too. Everything else the plugin depends on is a normal package: leave it alone.

### Requirements

- Linux or macOS (no Windows support yet)
- CPython 3.13+ built with a shared libpython — true for uv-managed Pythons, python.org installers, Homebrew, conda, and distro packages. Plain pyenv builds need `PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install ...`.

### Bundled plugins

The compatibility layers for `pytest-asyncio`, `anyio`'s pytest plugin, `pytest-mock`, `pytest-cov`, `pytest-split`, `pytest-benchmark` and `pytest-xdist`-style `-n` parallelism are built in — no separate plugin installs (the anyio layer runs tests through the installed `anyio` library's backends, so `anyio` itself must be in the environment as usual). Two ways to turn features off:

Per project or per run, like pytest (works with the prebuilt wheel):

```toml
[tool.pytest.ini_options]
addopts = "-p no:benchmark -p no:split"
```

At build time, when installing from source — bundled plugins are Cargo features, all enabled by default:

```toml
[tool.uv]
config-settings-package = { pytest-rs = { build-args = "--no-default-features --features asyncio,mock" } }
```

#### Type annotations

A suite that annotates its fixture parameters keeps working: the wheel installs
`pytest_mock`, `pytest_asyncio`, `pytest_cov` and `pytest_benchmark` as real,
`py.typed` packages, so

```python
from pytest_benchmark.fixture import BenchmarkFixture
from pytest_mock import MockerFixture

def test_x(mocker: MockerFixture, benchmark: BenchmarkFixture) -> None: ...
```

type-checks and imports without the corresponding distributions installed — which
is what keeps the real `pytest` out of the environment (see the note above). Each
declares the surface pytest-rs's own fixture provides; where a bundled plugin is
narrower than upstream, the missing attribute is left undeclared rather than
typed and broken, so a type checker tells you before a run does.

`pytest-split` has no importable API to mirror (`--splits`/`--group` are
CLI-only), and the anyio layer uses the installed `anyio` package's own types.

### Third-party plugins (not reimplemented, loaded as-is)

Installed `pytest11` entry points load through the `pytest` API shim — plugins pytest-rs does **not** reimplement can still work as-is. The supported surface includes fixtures, markers, `pytest_addoption` (plugin `--flags` and ini options), `config.stash`, custom hookspecs (`pytest_addhooks`), `pytest_runtest_protocol`/`pytest_runtest_call` hookwrappers, custom collectors (`pytest_collect_file` → `File`/`Item`), and terminal-reporter replacement (a plugin that unregisters the `terminalreporter` plugin and registers its own subclass takes over the output — pytest-rs suppresses its native rendering and drives the replacement through the same hooks pluggy would). Verified status:

| evidence | plugins |
|---|---|
| own upstream test suite runs under pytest-rs and gates CI (per-suite pass-rate in the **Third-party plugins** [conformance table](#conformance-testing) below) | `pytest-timeout`, `pytest-randomly`, `pytest-env`, `pytest-socket`, `pytest-snapshot`, `pytest-ruff`, `pytest-rerunfailures`, `pytest-order`, `pytest-repeat`, `pytest-instafail`, `pytest-icdiff`, `pytest-metadata`, `pytest-subtests`, `pytest-mypy`, `pytest-bdd`, `pytest-django`, `pytest-aiohttp`; `anyio`'s own plugin module also loads this way |
| functional smoke demo gates CI (`conformance/plugin_smoke.py`) | `Faker`, `time-machine`, `requests-mock`, `inline-snapshot` (snapshot assertions + `--inline-snapshot` flag), `pytest-run-parallel` (`--parallel-threads` really runs each test on N threads) |
| reporter replacement — terminal output byte-diffed against real pytest 9.2.0 | `pytest-pretty`, `pytest-sugar` (progress bar, instant failures; activates on a tty or `--force-sugar`) |
| not reimplemented yet | `pytest-html` (needs the report data model exposed); `syrupy` (serializer/extension framework) |

A plugin that fails to load stops the run, as in pytest 9.2: one that cannot be found is a usage error (exit 4), one that raises while importing (e.g. it reaches into pytest/pluggy internals the shim doesn't provide) an `Error while loading plugin` failure (exit 3). `-p no:NAME` and `PYTEST_DISABLE_PLUGIN_AUTOLOAD` opt out, like pytest.

Installing one of these into a pytest-rs environment needs care, since the plugin's own `pytest` dependency would reinstall the real distribution — see [Adding a third-party plugin without pulling `pytest` back in](#adding-a-third-party-plugin-without-pulling-pytest-back-in).

## Performance

Startup, collection, fixture orchestration, coverage measurement, and parallel workers are native Rust code. The main wins:

- **`--cov` runs** — coverage is collected via `sys.monitoring` (Python 3.12+ low-overhead instrumentation) instead of `coverage.py`'s tracing hooks. Typically **2–3x faster**, and the gap widens with suite size.
- **`-n` parallel runs** — workers fork off the already-warm parent interpreter by default (unix only), skipping per-worker interpreter/plugin/conftest import cost. Each forked worker still fires its own `pytest_configure` and collects/applies `pytest_collection_modifyitems` independently, so behavior matches a freshly spawned worker. Set `PYTEST_RS_DIST_SPAWN=1` to opt back into spawning a fresh subprocess per worker (upstream xdist's model) instead.
- **Large collections** — fixture resolution and parametrize expansion run in Rust; suites with thousands of tests see faster collection.

Benchmarks on open-source projects (macOS arm64, median of 3 warm runs), reproducible with [`bench/suites.sh`](bench/README.md) — clones each suite at a pinned tag, installs pytest-rs into its venv, and times both runners.

<!-- perf-results:start -->
| suite (tests) | mode | pytest | pytest-rs | speedup |
|---|---|---:|---:|---|
| marshmallow (1119) | `(plain)` | 0.43 s | 0.32 s | **1.3x** |
| marshmallow (1119) | `--cov` | 0.77 s | 0.34 s | **2.3x** |
| marshmallow (1119) | `-n 3 --cov` | 0.87 s | 0.29 s | **3.0x** |
| click (2459) | `(plain)` | 3.24 s | 2.37 s | **1.4x** |
| click (2459) | `--cov` | 4.57 s | 2.44 s | **1.9x** |
| click (2459) | `-n 3 --cov` | 3.32 s | 1.26 s | **2.6x** |
| networkx (6890) | `(plain)` | 30.09 s | 27.86 s | **1.1x** |
| networkx (6890) | `--cov` | 94.20 s | 33.34 s | **2.8x** |
| networkx (6890) | `-n 3 --cov` | 36.84 s | 15.48 s | **2.4x** |
<!-- perf-results:end -->

Small-to-medium suites see a **1.3–1.4x** speedup even without coverage, thanks to lower startup overhead. On large suites where test bodies dominate, the plain-mode gap narrows; the bigger wins come from `--cov` and `-n` parallelism. Try it on your own suite:

```sh
hyperfine -w 1 'pytest -q' 'pytest-rs -q'
hyperfine -w 1 'pytest --cov=mypkg' 'pytest-rs --cov=mypkg'
```

## Known limitations

- unix only (no Windows)
- no `--pdb` / debugger integration yet
- third-party pytest plugins are loaded via the `pytest11` entry point and the `pytest` API shim; plugins reaching deep into pytest internals may not work (see "Third-party plugins" above for verified examples)

## Conformance testing

Compatibility is verified by running the **upstream test suites** of the libraries pytest-rs reproduces, unchanged, under pytest-rs (`conformance/`).

Current results (`total = passed + failed + errors + skipped + deselected + known_failed`; `deselected` = tests that never run, excluded via `--deselect` in `conformance/suites.toml` because running them would be flaky or environmentally invalid; `known_failed` = tests that run normally but fail for a known, permanent, accepted reason (matched by exact nodeid against the run's own output, so a test that starts passing again is simply counted as `passed` instead of masking a real fix); both count against the total but not toward conformance; `files excluded` = whole files that also fail under vanilla pytest, out of scope; updated automatically by `conformance/runner.py` — see [conformance/RESULTS.md](https://github.com/Yasu-umi/pytest-rs/blob/main/conformance/RESULTS.md) for per-file detail):

<!-- conformance-results:start -->
_linux (CI-verified)_

**pytest & plugin ecosystem** (the APIs pytest-rs reimplements):

| suite | tag | passed | failed | errors | skipped | deselected | known_failed | total | conformant % | files all-pass | files run | files excluded |
|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| pytest | 9.2.0 | 3271 | 0 | 0 | 61 | 0 | 29 | 3361 | 99.1% | 55 | 55 | 62 |
| pytest-asyncio | v1.5.0 | 268 | 0 | 0 | 3 | 0 | 0 | 271 | 100.0% | 30 | 30 | 0 |
| pytest-mock | v3.17.0 | 158 | 0 | 0 | 1 | 0 | 2 | 161 | 98.8% | 1 | 1 | 0 |
| pytest-cov | v7.1.0 | 205 | 0 | 0 | 3 | 0 | 1 | 209 | 99.5% | 1 | 1 | 0 |
| pytest-xdist | v3.8.0 | 96 | 0 | 0 | 2 | 0 | 0 | 98 | 100.0% | 1 | 1 | 6 |
| pytest-split | 0.11.0 | 59 | 0 | 0 | 0 | 0 | 0 | 59 | 100.0% | 1 | 1 | 3 |
| pytest-benchmark | v5.3.1 | 158 | 0 | 0 | 10 | 0 | 1 | 169 | 99.4% | 9 | 10 | 5 |
| anyio | 4.16.0 | 4737 | 0 | 0 | 20 | 0 | 0 | 4757 | 100.0% | 29 | 29 | 0 |

**Third-party plugins** (not reimplemented — their own upstream test suites run under pytest-rs, loaded via the `pytest11` entry-point shim):

| suite | tag | passed | failed | errors | skipped | deselected | known_failed | total | conformant % | files all-pass | files run | files excluded |
|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| pytest-aiohttp | v1.1.1 | 7 | 0 | 0 | 0 | 0 | 0 | 7 | 100.0% | 2 | 2 | 0 |
| pytest-timeout | 2.4.0 | 42 | 0 | 0 | 1 | 0 | 0 | 43 | 100.0% | 1 | 1 | 0 |
| pytest-mypy | v1.1.0 | 76 | 0 | 0 | 2 | 0 | 0 | 78 | 100.0% | 1 | 1 | 0 |
| pytest-ruff | v0.5 | 10 | 0 | 0 | 0 | 0 | 0 | 10 | 100.0% | 1 | 1 | 0 |
| pytest-subtests | v0.15.0 | 31 | 1 | 0 | 0 | 0 | 2 | 34 | 91.2% | 0 | 1 | 0 |
| pytest-metadata | 3.1.1 | 10 | 0 | 0 | 0 | 0 | 0 | 10 | 100.0% | 1 | 1 | 0 |
| pytest-snapshot | v0.9.0 | 106 | 0 | 0 | 0 | 0 | 1 | 107 | 99.1% | 3 | 3 | 0 |
| pytest-icdiff | 0.5 | 10 | 0 | 0 | 0 | 0 | 2 | 12 | 83.3% | 1 | 1 | 0 |
| pytest-socket | 0.8.1 | 111 | 0 | 0 | 0 | 0 | 1 | 112 | 99.1% | 8 | 8 | 0 |
| pytest-order | v1.5.0 | 142 | 0 | 0 | 0 | 0 | 0 | 142 | 100.0% | 17 | 17 | 0 |
| pytest-repeat | v0.9.4 | 16 | 0 | 0 | 0 | 0 | 0 | 16 | 100.0% | 1 | 1 | 0 |
| pytest-instafail | v0.5.0 | 63 | 0 | 0 | 0 | 0 | 0 | 63 | 100.0% | 1 | 1 | 0 |
| pytest-env | 1.8.6 | 159 | 0 | 0 | 0 | 0 | 0 | 159 | 100.0% | 3 | 3 | 0 |
| pytest-rerunfailures | 16.7 | 225 | 13 | 0 | 10 | 0 | 0 | 248 | 94.8% | 0 | 1 | 0 |
| pytest-randomly | 5.1.0 | 46 | 0 | 0 | 0 | 0 | 1 | 47 | 97.9% | 1 | 1 | 0 |
| pytest-bdd | 9.0.1 | 45 | 100 | 0 | 1 | 0 | 0 | 146 | 31.5% | 7 | 35 | 0 |
| pytest-django | v4.14.0 | 237 | 0 | 0 | 1 | 0 | 0 | 238 | 100.0% | 14 | 15 | 0 |

**Real-world projects** (their suites run unchanged, as drop-in evidence):

| suite | tag | passed | failed | errors | skipped | deselected | known_failed | total | conformant % | files all-pass | files run | files excluded |
|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| click | 8.5.1 | 2373 | 61 | 0 | 24 | 0 | 0 | 2458 | 97.5% | 42 | 43 | 0 |
| jinja | 3.1.6 | 909 | 0 | 0 | 0 | 0 | 0 | 909 | 100.0% | 22 | 22 | 0 |
| marshmallow | 4.4.0 | 1192 | 0 | 0 | 0 | 0 | 0 | 1192 | 100.0% | 12 | 12 | 3 |
| rich | v15.0.0 | 955 | 0 | 0 | 20 | 0 | 6 | 981 | 99.4% | 61 | 63 | 0 |
| sqlglot | v30.33.0 | 1613 | 0 | 0 | 0 | 0 | 0 | 1613 | 100.0% | 58 | 60 | 0 |
| httpx | 0.28.1 | 1408 | 2 | 0 | 1 | 0 | 7 | 1418 | 99.4% | 30 | 31 | 0 |
| httpx2 | v2.16.2 | 1807 | 0 | 0 | 0 | 0 | 2 | 1809 | 99.9% | 36 | 36 | 0 |
| starlette | 1.10.0 | 1412 | 0 | 0 | 2 | 0 | 0 | 1414 | 100.0% | 31 | 31 | 0 |
| attrs | 26.1.0 | 1379 | 0 | 0 | 6 | 0 | 0 | 1385 | 100.0% | 23 | 25 | 0 |
| more-itertools | v11.2.1 | 765 | 0 | 0 | 0 | 0 | 0 | 765 | 100.0% | 2 | 2 | 0 |
| werkzeug | 3.1.9 | 955 | 0 | 0 | 1 | 25 | 0 | 981 | 97.5% | 24 | 25 | 0 |
| fastapi | 0.165.0 | 5221 | 0 | 0 | 6 | 0 | 0 | 5227 | 100.0% | 539 | 550 | 0 |
| packaging | 26.3 | 62423 | 0 | 0 | 0 | 0 | 0 | 62423 | 100.0% | 17 | 31 | 0 |
| pandas | v3.1.1 | 188852 | 945 | 304 | 24877 | 0 | 6 | 214984 | 99.4% | 886 | 978 | 3 |
| networkx | 3.7 | 9128 | 0 | 0 | 61 | 0 | 0 | 9189 | 100.0% | 261 | 268 | 0 |
| pydantic | v2.14.4 | 10984 | 0 | 0 | 982 | 0 | 14 | 11980 | 99.9% | 128 | 133 | 0 |
| scikit-learn-1 | 1.9.1 | 8443 | 0 | 0 | 6630 | 0 | 0 | 15073 | 100.0% | 79 | 87 | 0 |
| scikit-learn-2 | 1.9.1 | 5091 | 0 | 0 | 1892 | 0 | 0 | 6983 | 100.0% | 52 | 58 | 0 |
| scikit-learn-3 | 1.9.1 | 9275 | 0 | 0 | 2540 | 0 | 3 | 11818 | 100.0% | 107 | 114 | 0 |
<!-- conformance-results:end -->

The suites are included as **shallow git submodules** under `conformance/suites/` at the pinned release tags. Initialize them once after cloning:

```sh
git submodule update --init --depth 1
```

Then run the full conformance harness:

```sh
cargo build
uv run --no-project python conformance/runner.py --local   # uses submodules
uv run --no-project python conformance/runner.py           # re-clones from upstream (CI mode)
```

| Project | License | Tag |
|---|---|---|
| [pytest](https://github.com/pytest-dev/pytest) | MIT | 9.2.0 |
| [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) | Apache-2.0 | v1.5.0 |
| [pytest-mock](https://github.com/pytest-dev/pytest-mock) | MIT | v3.17.0 |
| [pytest-cov](https://github.com/pytest-dev/pytest-cov) | MIT | v7.1.0 |
| [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) | MIT | v3.8.0 |
| [pytest-split](https://github.com/jerry-git/pytest-split) | MIT | 0.11.0 |
| [pytest-benchmark](https://github.com/ionelmc/pytest-benchmark) | BSD-2-Clause | v5.3.1 |

pytest-rs reimplements the public APIs of these projects, plus [anyio](https://github.com/agronholm/anyio)'s pytest plugin (MIT). Parts of the bundled Python shims are ports of upstream code; see [THIRD-PARTY-NOTICES.md](https://github.com/Yasu-umi/pytest-rs/blob/main/THIRD-PARTY-NOTICES.md). Credit for the API design and the test suites belongs to their respective authors.

## License

This project is licensed under the MIT License. See the LICENSE file for more details.

