Plugins¶
How rstest loads your installed pytest plugins, which ones are tested, and which behave differently under the parallel pool.
How loading works¶
rstest workers run a vendored pytest core, and plugins load against it
through the standard pytest11 entry points: the same mechanism pytest
uses. Class identity holds: rstest depends on the real
pluggy, and the vendored core's
classes live at their usual _pytest.* import paths, so plugins that
isinstance-check or import internals find what they expect. No plugin
re-installation, configuration, or porting.
Plugin command-line flags forward like any pytest flag, except the
few flag names rstest owns (such as
--timeout and --reruns): on the command line rstest takes those and the
plugin never sees them. Put such a flag after -- to hand it to the plugin
instead, and note that rstest does not read its own flags from addopts
(details). Plugin ini
options are read normally.
Because plugins load into the vendored core, each plugin's own code must
support pytest 9, and a pytest<9 install pin has no effect at runtime (rstest
warns about such pins); see
Plugin versions vs the vendored core.
Looking for a specific plugin?
See the top-100 plugin compatibility matrix,
covering how the 100 most-downloaded plugins behave under the pool, each marked
verified (V) or inferred (i), and
Plugins exercised by the corpus, the
runtime inventory of plugins real suites load and pass under rstest.
Exercised continuously¶
These load and pass per-test outcome parity against pytest baselines in rstest's compatibility battery, on real suites:
- pytest-django (SQLite only so far)
- pytest-asyncio
- pytest-aiohttp
- hypothesis
- pytest-mock
- pytest-cov (see Coverage)
Special-cased¶
- pytest-xdist: neutralized inside workers (rstest owns parallelism);
its hookspecs stay importable for plugins that implement them. Of the
controller-side hooks,
pytest_configure_node,pytest_testnodeready, andpytest_testnodedownare emulated (called). The rest (pytest_xdist_make_scheduler,pytest_xdist_auto_num_workers,pytest_xdist_newgateway,pytest_xdist_setupnodes,pytest_xdist_node_collection_finished,pytest_handlecrashitem) are never called: scheduling and crash handling are the Rust orchestrator's job and are not extensible from Python. See Hook coverage. - pytest-rerunfailures: inside pool workers rstest
unregisters the plugin
and handles reruns itself, crash-aware, honoring
@mark.flaky. rstest's--rerunsfire at every worker count, including-n 0/1. At-n 0with no--rerunsthe plugin keeps its own behavior.
Tested compatibility¶
The common plugin stack and other ecosystem plugins, tiered with the
same verdicts as the top-100 matrix: β
Works = correct in parallel;
π¦ Native = works, but rstest has a built-in that replaces it;
β οΈ Caveat = works with a stated limitation; πΆ -n 0 = run
single-worker for this plugin's feature; π΄ Silent = produces nothing at
-n β₯ 2 (use -n 0 or rstest's native equivalent); β N/A =
parallelism does not apply: the plugin is unaffected by it (assertion,
fixture or format helpers) or, like pytest-xdist, is neutralized because
rstest is the parallel runner.
The V/i column matches the top-100 matrix: V = runtime-verified (an
e2e gate or a corpus suite loads the plugin under the parallel pool),
V* = partly verified (the note says which part), i = inferred from
the plugin's design with no automated check yet, so confirm an i row with
one -n 0 and one -n auto run on your own suite.
For the broader picture (the 100 most-downloaded plugins, each with a verified/inferred marker), see the top-100 compatibility matrix.
| Plugin | Tier | V/i | Note |
|---|---|---|---|
| pytest-django | β Works | V* | per-worker test DB suffixed by workerid. Verified on SQLite only |
| pytest-asyncio | β Works | V | per-test event loop; rstest provides the worker context it sniffs |
| hypothesis | β Works | V | property-based per worker. Known gap: the shared .hypothesis example DB is untested past -n 8; see known gaps for the per-worker-DB mitigation |
| pytest-cov | π¦ Native | V | rstest combines coverage across workers via native --cov. Pass --cov on the rstest command line: from addopts alone a parallel run writes no report. See Coverage |
| pytest-mock | β Works | V | per-test mocker fixture |
| pytest-timeout | π¦ Native | V | rstest's own --timeout and @pytest.mark.timeout replace it; see pytest-timeout before removing it |
| pytest-env | β Works | i | env vars are set by its pytest_load_initial_conftests hook, which runs in every worker session |
| pytest-socket | β Works | V | loads under the pool in two corpus suites; --allow-hosts blocking gated at -n 2 (--disable-socket not yet exercised) |
| pytest-forked | β οΈ Caveat | V | Broken on pytest 9.2 up to 1.7.5 (every forked test fails with EXITED with status 3, under plain pytest too); needs the release carrying pytest-forked#112. Once fixed: --forked (after --) or @pytest.mark.forked runs each test in a forked child inside the worker: module state can't leak between tests, and a crashing child fails only its test (counted failed, as in pytest). Unix only. Use it as a stopgap for an ISOLATION finding, or for a test that segfaults |
| pytest-repeat | β Works | i | @mark.repeat(N) expands at collection, so the copies are ordinary items that distribute across workers |
| freezegun | β Works | V | in-process time freezing is per-worker (the freezegun, aiohttp, itsdangerous, langchain and python-dateutil corpus suites load it in parallel). The pytest-freezer and pytest-freezegun wrappers use the same model but are not gated (i). Keep now() out of parametrize IDs unless every worker computes the same string (see unstable parametrize IDs) |
| pytest-benchmark | πΆ -n 0 |
V | auto-disables at -n β₯ 2 (sees the pool as xdist); run benchmarks at -n 0 and read numbers from --benchmark-json (the stats table isn't painted: rstest owns the terminal) |
| pytest-order | β οΈ Caveat | i | the e2e gate covers pytest-ordering, same model. Ordering only holds within a worker at -n β₯ 2; use -n 0, or --dist loadfile/loadscope to keep an ordered group on one worker |
| pytest-randomly | β Works | V | rstest supplies one shared seed; see below |
| pytest-random-order | β Works | V | rstest supplies one shared seed; global order follows rstest's dispatch. See below |
| pytest-mypy | β Works | V | each worker type-checks its own subset; see below |
| pytest-rerunfailures | π¦ Native | V | unregistered inside pool workers; rstest owns reruns (--reruns, --only-rerun, @mark.flaky(reruns=N), see Special-cased). The mark's budget, condition, only_rerun, rerun_except and reruns_delay are honored (Flaky tests). A --reruns in addopts works at -n 0 but silently does nothing in the pool |
| pytest-html | π΄ Silent | V | at -n β₯ 2 no report is written: a silent no-op, not a crash. Use rstest's native --html, or see HTML & aggregated reporting for the other paths. |
| pytest-sugar | πΆ -n 0 |
V | terminal rendering is not painted at -n β₯ 2: rstest owns the terminal. Non-visual behavior is unaffected; run at -n 0 when you want its rendering |
| pytest-xdist | β N/A | V | neutralized inside workers: rstest is the parallel runner and xdist's options parse but stay inert. Keep it installed while a conftest implements its hooks (Controller-side hooks) |
Plugins that expect an xdist controller¶
The recurring fault line: plugins that read xdist-controller-injected
workerinput keys would crash under a pool with no controller to supply
them, so rstest closes these per plugin.
Derivable keys are synthesized in each worker, as one run-level value every worker agrees on:
- pytest-randomly gets
randomly_seed, derived from the run uid. To reproduce a run's order, pass--randomly-seed=<n>(it wins over the synthesized key), or pin the run uid withRSTEST_RUN_UID=<hex>(the seed is that hex value's low 32 bits). - pytest-random-order reads
workerinput["random_order_seed"]wheneverworkerinputexists, even with reordering off (the default). rstest seeds that key with the plugin's owndefault:prefix, so order is untouched unless you pass--random-order[-bucket|-seed], and an explicit--random-order-seed=<n>is honored. Global execution order still follows rstest's duration-first dispatch, so use-n 0or native--shufflefor a strict end-to-end shuffle.
Controller-service keys are handled by each worker acting as its own controller:
- pytest-mypy is handed a unique per-worker
mypy_config_stash_serializedcache path. mypy runs lazily on the first mypy item in each worker, so each worker type-checks its own subset and errors surface the same at-n autoand-n 0. If the path can't be provisioned, the plugin is unregistered (run mypy at-n 0). - pytest-retry starts its own report server per worker (how).
- pytest-rerunfailures is unregistered; rstest owns reruns instead (how).
The one still-unsupported case in this table is pytest-html (see its row).
Where a plugin is risky, rstest also ships a native equivalent:
--shuffle (βpytest-randomly),
--reruns/--only-rerun (βpytest-rerunfailures), --timeout and
--worker-timeout (βpytest-timeout).
pytest-timeout¶
rstest has a built-in --timeout and
honors @pytest.mark.timeout itself at every worker count, even without
--timeout. The plugin's ini timeout = still fires in both modes, so with
the plugin installed a marked test gets two SIGALRM timers (rstest's is
installed last, so its Timeout error is the one you see), and a
command-line --timeout never reaches the plugin. Pick one: uninstall
pytest-timeout, or disable it with -p no:timeout.
Before you uninstall it, move the ini setting. Without the plugin, an ini
timeout = N is dropped (pytest warns Unknown config option: timeout) and
addopts = --timeout N is a usage error (unrecognized arguments), because
rstest does not read its own flags from addopts, and [tool.rstest] has no
timeout key. The working path is rstest --timeout N on the command line (CI
script, Makefile).
Options with no equivalent. The plugin's timeout_method,
timeout_func_only and session_timeout are dropped the same way: rstest's
timeout always covers the call phase only and always uses a signal, and
nothing bounds the whole session.
Windows. --timeout and @pytest.mark.timeout cannot interrupt the test
in-process there; only the per-test
hang watchdog
applies (Running on Windows: timeouts). The same
watchdog, or an explicit --worker-timeout, is the backstop for C-extension
deadlocks on any platform.
HTML & aggregated reporting under parallelism¶
pytest-html goes dark at -n β₯ 2, as do the other controller-aggregating
reporters (the silent-no-op class). You do not have to choose between parallel
speed and a contributor-facing report: run the suite once in parallel, then
emit the report from the merged artifacts rstest writes. Nothing reruns.
The reason this works: --junitxml and --report-json are intercepted by
rstest and rendered from merged results, not forwarded to per-worker
sessions (which would clobber a shared file). Both are whole-suite documents
at any worker count, -n 0 through -n auto.
JUnit XML: for CI dashboards (native, parallel)¶
Most CI report surfaces (GitHub Actions test summaries, GitLab, Jenkins,
Buildkite) consume JUnit XML. --junitxml gives you one merged file
straight from the parallel run:
One file, all workers merged, pytest classname conventions. Flaky passes
(green after --reruns) carry <property name="flaky" value="true"/> so
dashboards track them without parsing anything else. This is the preferred
path when your goal is CI-visible results, not a standalone HTML page.
HTML: from --report-json (parallel run, no rerun)¶
When you specifically want an HTML artifact for contributors, generate it
from the parallel run's --report-json
snapshot, the full merged per-test outcome document:
$ rstest -n auto --report-json results.json # fast parallel run
$ python render_report.py results.json report.html # cheap, no tests run
The report generator is a few lines over the stable schema. The
meta.counts block is the terminal summary line verbatim (never re-derive
it by walking tests), and each test carries its phase outcomes,
duration, and longrepr on failure:
# render_report.py
import html, json, sys
doc = json.load(open(sys.argv[1]))
c = doc["meta"]["counts"]
rows = []
for nodeid, t in sorted(doc["tests"].items()):
if "failed" in (t.get("setup"), t.get("teardown")):
outcome = "error" # counted under meta.counts.errors, as pytest does
else:
outcome = t.get("call", t.get("setup", "skipped")) # skipped tests have no call phase
detail = html.escape(t.get("longrepr", t.get("skip_reason", "")))[:2000]
rows.append(
f"<tr class={outcome!r}><td>{html.escape(nodeid)}</td>"
f"<td>{outcome}</td><td>{t.get('duration', 0):.4f}s</td>"
f"<td><pre>{detail}</pre></td></tr>"
)
open(sys.argv[2], "w").write(
f"<h1>{c['passed']} passed, {c['failed']} failed, {c['errors']} errors, "
f"{c['skipped']} skipped "
f"({doc['meta']['duration_seconds']:.1f}s, {doc['meta']['workers']} workers)</h1>"
"<table><tr><th>test</th><th>outcome</th><th>time</th><th>detail</th></tr>"
+ "".join(rows)
+ "</table>"
)
This keeps the parallel wall-time win: the only extra cost is parsing a
JSON file. Style it however your contributors expect; the schema is
versioned (meta.schema) and increment-only, so the script won't silently
break on upgrade.
pytest-html's exact format: -n 0 reporting pass¶
If a workflow depends on pytest-html's specific HTML output and nothing
else will do, run a dedicated single-worker (-n 0) pass for the report only:
$ rstest -n auto # gate on this, the fast run
$ rstest -n 0 -- --html=report.html # report only; single session, no workerinput
The -- matters: rstest owns a command-line --html and renders its own
merged report from it at every worker count, so rstest -n 0 --html
report.html never reaches pytest-html. Arguments after -- go straight to
the pytest session (so does an --html set in addopts).
This reruns the suite serially, so use it only when the exact pytest-html
layout is a hard requirement. Native --html, JUnit, and --report-json
avoid the second run entirely.
Keep that pass at -n 0. rstest's parallel-run warning (see
the silent-no-op class) does not cover --html,
because on the command line --html is rstest's own report, so a
pytest-html --html that arrives after -- or through addopts at
-n β₯ 2 writes nothing and nothing warns you.
Checking an unlisted plugin¶
The lists above aren't exhaustive: your suite likely runs plugins not named here. Probe one yourself in a minute:
- Run a slice of your suite at
-n 0to establish that the plugin works at all under rstest's vendored core. - Run the same slice at
-n 2. If it now crashes (commonly aKeyErroron aworkerinputkey atpytest_configure), the plugin depends on an xdist-controller-injected value rstest doesn't set: run it at-n 0or find a native equivalent. - If it runs but results look wrong (ordering, benchmark timings, a report file not written), it's likely order- or terminal-sensitive: see the caveat tiers above for the pattern.
rstest try is a fast first pass: it runs your suite under pytest and
under rstest -n auto and flags outcome differences, plugins included. It
also lists any installed plugin or conftest that expects an xdist controller.
To get that list on a normal run, pass
--warn-on-dead-master-path:
it reads the plugin code, so it catches the crash (step 2) and the silent
no-op (below) before you run anything at -n 2.
Hook coverage¶
rstest runs a real pluggy inside each
worker, so every conftest/plugin hook runs per-worker exactly as in pytest.
The exceptions are hooks whose result depends on there being a single
coordinating process, because rstest's coordinator is the Rust orchestrator,
not a Python controller. This table is the precise contract at -n β₯ 2:
| Hook | Behavior at -n β₯ 2 |
Why |
|---|---|---|
pytest_configure / pytest_unconfigure |
Runs per worker | Standard per-session hook |
pytest_collection_modifyitems |
Deselection honored; reordering ignored | Dispatch is index-into-verified-collection, duration-first: use -n 0 or an affinity --dist mode to preserve order (xdist hooks) |
pytest_terminal_summary and other terminal-painting hooks |
Runs per worker, but custom terminal output is not shown: rstest owns the terminal | The orchestrator renders one merged terminal; use -n 0 when you want a plugin's own rendering |
pytest_runtest_protocol (custom replacements) |
Runs, but interplay with dispatch only exercised for the plugins listed above | Dispatch owns nextitem/phase streaming: report surprises |
pytest_configure_node |
Emulated (called) per worker | xdist controller-side hook: xdist hooks |
pytest_testnodeready / pytest_testnodedown |
Emulated; testnodedown for a crashed worker runs on a survivor |
Best-effort, weaker than xdist |
pytest_xdist_make_scheduler |
Not emulated (never called) | Scheduling lives in Rust, not extensible from Python |
pytest_xdist_auto_num_workers |
Not emulated (never called) | Worker count is rstest's decision |
pytest_xdist_newgateway |
Not emulated (never called) | No execnet gateways |
pytest_xdist_setupnodes |
Not emulated (never called) | No controller node setup |
pytest_xdist_node_collection_finished |
Not emulated (never called) | No controller collection phase |
pytest_handlecrashitem |
Not emulated (never called) | Crash handling lives in Rust |
pytest_xdist_rsyncstart / pytest_xdist_rsyncfinish |
Not emulated (never called) | No rsync to remote gateways |
pytest_xdist_getremotemodule |
Not emulated (never called) | No remote execnet workers |
The silent-no-op class¶
One failure mode is worth generalizing, because it hits a whole category of
plugins, not just pytest-html. A plugin that
decides "am I the xdist controller?" with not hasattr(config, "workerinput") will
silently do nothing under the rstest pool: every rstest worker carries a
workerinput, so the controller-only branch never fires, and nothing crashes to
tell you.
This is why pytest-html writes no report at -n β₯ 2 (it registers its
report writer only on a node without workerinput), and why
report-aggregator plugins in general (anything that merges all workers'
results into one artifact from a central process) go dark under parallelism.
Merging every worker into one file needs a single Python controller process,
which rstest doesn't run: the Rust orchestrator owns the merge, and workers
are isolated sessions.
Rule of thumb: if a plugin's job is to aggregate across workers from the
controller, assume it needs -n 0 until proven otherwise. rstest ships native,
merged-from-the-orchestrator equivalents for the common ones (--junitxml,
--report-json, --cov, native --html), which are whole-suite documents at
any worker count.
rstest warns you automatically. When a parallel run (-n β₯ 2) is invoked
with a flag whose plugin goes dark under the pool, rstest prints a heads-up
before the run naming the plugin and the parallel-safe alternative; you don't
have to remember the matrix:
$ rstest -n auto --report-log run.jsonl
rstest: warning: --report-log (pytest-reportlog) produces no usable report under
the parallel pool β it aggregates on the xdist master, which rstest has none of;
use rstest's native --report-json, or run -n 0. See docs/reference/top-100-plugins.md
Covered flags: --json-report (pytest-json-report), --report-log
(pytest-reportlog), --ctrf (pytest-json-ctrf), --nunit-xml (pytest-nunit),
--md (pytest-md) and --benchmark* (pytest-benchmark, which auto-disables).
The same warning also covers --csv (pytest-csv), which does not go dark but
writes a racy per-worker CSV under the pool (rated β οΈ Caveat in the
top-100 matrix).
The warning is argv-driven: it fires on the flag, so it never mistakes
rstest's own --html / --junitxml / --report-json (which are rendered
from merged results and are parallel-safe) for a hazard, and it stays silent
at -n 0 where the plugin's own controller branch runs.
For plugins and conftests outside that flag list, pass
--warn-on-dead-master-path
(or run rstest try, which turns it on): it reads their code for a
controller-only branch that does real work and names each one.
Self-audit: catch a silent no-op in your own plugins¶
The danger of this class is that nothing errors: a home-grown reporter or
aggregator just stops producing its artifact at -n β₯ 2. You can flush it
out mechanically: run the same slice at -n 0 and at -n 2, each into
its own empty directory, then diff the files each run produced. Anything a
plugin writes at -n 0 but not at -n 2 (or writes empty) is a silent
no-op.
#!/usr/bin/env bash
# silent-noop-audit.sh: flag plugin artifacts that vanish under the pool.
# Usage: ./silent-noop-audit.sh tests/some_slice
set -euo pipefail
slice="${1:-tests}"
audit() { # $1 = worker count, $2 = output dir
rm -rf "$2"; mkdir -p "$2"
# -p no:cacheprovider keeps .pytest_cache out of the diff; rstest still
# writes .rstest_cache, so find skips it. Add your plugin's output flags
# here if it needs one (e.g. --html "$2/report.html").
( cd "$2" && rstest -n "$1" -p no:cacheprovider "$OLDPWD/$slice" >stdout.log 2>&1 ) || true
( cd "$2" && find . -type f ! -empty ! -path './.rstest_cache/*' | sort ) >"$2.files"
}
audit 0 audit-n0
audit 2 audit-n2
echo "== files present at -n 0 but MISSING or EMPTY at -n 2 (silent no-op suspects) =="
comm -23 audit-n0.files audit-n2.files
echo "== plugin lines in -n 0 stdout absent from -n 2 stdout (terminal-owned output) =="
diff <(grep -v '^$' audit-n0/stdout.log) <(grep -v '^$' audit-n2/stdout.log) | grep '^<' || true
Read the two lists:
- A file in the first list: a plugin wrote it serially and not under the
pool. That's the silent no-op (pytest-html's
report.htmlshows up here). Move that report to a-n 0/-n 1pass, or switch to a native merged-from-orchestrator artifact (--html,--junitxml,--report-json). - Lines in the second list are usually just terminal-painting plugins (rstest owns the terminal), which is expected and not a bug, unless a line represents a data side effect the plugin only performs on the controller. If so, treat it like the first list.
One caveat the diff can't see: a plugin that writes the same path at both
worker counts but with less in it at -n 2 (e.g. only one worker's
share). For those, compare sizes or contents of the shared artifact, not
just its presence. When in doubt, the fallback is unchanged:
generate that artifact at -n 0.
Known limits¶
- Plugins that render the terminal (pytest-sugar, pytest-rich and
similar progress UIs) don't paint at
-n β₯ 2: rstest owns the terminal. Their non-visual behavior is unaffected; use-n 0when you specifically want their rendering. - Plugins registering custom
pytest_runtest_protocolreplacements run, but interplay with rstest's item dispatch is only exercised for the plugins listed above. Report surprises.