Skip to content

Environment variables

Environment variables rstest sets for tests and plugins, and the ones it reads to change its own behavior.

Read by tests and plugins (public contract)

Variable Value Meaning
RSTEST_WORKER_ID gw0, gw1, ... identity of the worker running this test; unset in -n 0/-n 1 mode (unless --reruns makes it a one-worker pool: then gw0)
RSTEST_WORKER_COUNT integer pool size; unset in -n 0/-n 1 mode (1 under --reruns)
PYTEST_XDIST_WORKER gw0, gw1, ... pytest-xdist's env var, set for compatibility, so plugins and conftests that grep it work unedited; unset in -n 0/-n 1 mode (gw0 under --reruns)
PYTEST_XDIST_WORKER_COUNT integer xdist's pool-size var, same compatibility contract; unset in -n 0/-n 1 mode (1 under --reruns)
PYTEST_XDIST_TESTRUNUID opaque string xdist's run-uid var, the same value as RSTEST_RUN_UID; set in pool workers (including the --reruns one-worker pool), cleared in -n 0/-n 1 mode (like PYTEST_XDIST_WORKER)
RSTEST_RUN_UID opaque string one uid per run, shared by every worker (and every project of a monorepo run); also exposed as workerinput["testrun_uid"] and workerinput["testrunuid"] (xdist's spelling)
RSTEST_MONO_PROJECT relative path set inside a monorepo child run to that project's path (e.g. libs/core); unset otherwise. rstest also reads it: when it is set, monorepo discovery is skipped and the run is a single-project run, so don't export it yourself

Plugins that read pytest-xdist's workerinput get the same information via request.config.workerinput["workerid"] / ["workercount"] / ["testrunuid"]: that path works under both runners.

An "unset" above means the variable is absent in the worker: rstest clears these before starting each worker, so a RSTEST_WORKER_ID or PYTEST_XDIST_WORKER exported in your shell or CI (or by an outer rstest, when a test runs rstest itself) never reaches a test. In a parallel run each worker sets its own real values. request.config.workerinput always carries the real values.

Set by the orchestrator (internal)

RSTEST_BASETEMP, RSTEST_SEND_IDS, RSTEST_DOCTOR, RSTEST_TIMEOUT, RSTEST_LEAKCHECK, RSTEST_WARM_RECORD, RSTEST_WARM_MANIFEST, RSTEST_WARM_RESULT, RSTEST_DEAD_MASTER_SCAN, RSTEST_DEBUGPY_PORT, RSTEST_STREAM_OUTPUT, RSTEST_JUNITXML, RSTEST_RERUNS (set to 1 under a global --reruns, so a session's own -x / --maxfail doesn't count failed attempts the orchestrator may retry), RSTEST_QUARANTINE (the --quarantine file patterns, one anchored regex per line, exempt from -x / --maxfail the same way), RSTEST_AUTO_QUARANTINE (the auto-quarantined nodeids, one per line, exempt the same way) and RSTEST_AUTO_QUARANTINE_MAX (their cap, a percent of the session's tests), plus RSTEST_NETWORK (record under --doctor) and RSTEST_NETWORK_ALLOW (the network-allow entries, one per line) coordinate workers and may change between versions. Don't depend on them. rstest clears them before starting each worker and sets only the ones the run needs (for example RSTEST_DOCTOR only under --doctor, --doctor-json, --doctor-md or --doctor-fail-on), and it never reads them from its own environment, so a value you export has no effect: export RSTEST_DOCTOR=1 turns on nothing (pass --doctor). RSTEST_RUN_UID is the exception, see below.

Two more are set by rstest for its own use: RSTEST_RECORD (the output path rstest try gives the recorder plugin in its plain-pytest run) and RSTEST_DEBUGPY_LISTENING (set inside a --debug worker once debugpy is listening, so a re-imported child process doesn't bind the port twice). The coverage post-processing step (rstest_worker.covtool, run after a --cov run) also gets RSTEST_ROOTDIR, the project root its coverage-index keys are relative to, so a run from a subdirectory writes the same keys as one from the root.

Honored from the environment

Variable Effect
RSTEST_RUN_UID the run uid to use instead of generating one. Every worker sees it as RSTEST_RUN_UID and workerinput["testrun_uid"]. Set the same value on every CI shard to give them one shared run uid (for example RSTEST_RUN_UID=${{ github.run_id }}-${{ github.run_attempt }}). A monorepo run passes its own to each project's rstest this way
VIRTUAL_ENV worker interpreter discovery (first after --python)
NO_COLOR a non-empty value turns color off, and with it the live footer, so a terminal gets no escape sequences (see Color precedence)
FORCE_COLOR a non-empty value colors the output even when piped, matching the workers' colored assertion diffs (pytest reads it too). NO_COLOR wins over it. Color alone never brings back the live footer off a terminal
PY_COLORS 1 forces color on, 0 forces it off; beats NO_COLOR and FORCE_COLOR, as in pytest
TERM dumb means no color and no live footer on a terminal, as pytest does (Emacs compile buffers)
CI any value other than empty, 0 or false turns the live footer and the bar default off even on a pty (Buildkite, docker -t): the run prints dots and no cursor movement. Color stays as decided above
COLUMNS the terminal width for the live footer when the terminal can't report its size (default 80); footer lines are cut to fit so they never wrap
PYTEST_ADDOPTS read by the vendored core, exactly as under pytest. rstest-owned flags placed here (--reruns, --junitxml, --timeout, ...) are not seen by rstest; see CLI
RSTEST_CACHE relocates the project cache directory (default .rstest_cache at the pytest rootdir); see Cache location
RSTEST_CACHE_REMOTE default for --cache-remote (the flag wins)
RSTEST_CACHE_REMOTE_TOKEN bearer token sent to an http(s):// cache remote, hidden from test processes; see Remote cache token
RSTEST_NO_REPLAY_JOURNAL set to 1 to stop parallel runs writing a replay journal; empty, 0 and false leave journaling on
RSTEST_CACHE_KEEP_LAST cache-compact / auto-compaction retention: keep the newest N segments loose (default for --keep-last)
RSTEST_CACHE_MAX_AGE retention by age: keep segments younger than this loose, e.g. 30d (default for --max-age)
RSTEST_CACHE_COMPACT_THRESHOLD default for --cache-compact-threshold; an unparseable value is reported, not ignored
RSTEST_WORKER_PATH extra directory prepended to the workers' PYTHONPATH to locate the rstest_worker package (for unusual installs where the project interpreter can't import it)
RSTEST_MAX_MESSAGE_BYTES cap on one worker-to-orchestrator message (default 256 MiB); raise it only if a huge suite hits the limit
RSTEST_WALL_TTL_DAYS how long a project's recorded wall time (.rstest_cache/wall.json, used by the monorepo planner to weight projects) stays valid. Default 30; 0 keeps it forever
RSTEST_CACHE_DIR base dir for the interpreter-probe cache only, not .rstest_cache/; see Interpreter-probe cache
RSTEST_FLAKE_RETENTION_DAYS how long a test's flake/failure history (.rstest_cache/flakes.json) stays relevant. A test with no flake or failure inside this window reads as fixed: its entry is dropped and it stops carrying "flaked _N_x before" annotations. Defaults to 90; 0 keeps history forever. Also ages the per-test run history (.rstest_cache/history.msgpack)
RSTEST_HISTORY_RUNS how many runs of each test .rstest_cache/history.msgpack keeps. Everything history-based reads that window: --auto-quarantine (the flips), --durations-regress (the median baseline), rstest explain, rstest flaky, rstest report, the --html strip and --doctor's TIMEOUTS and DURATION DRIFT. Default 50, minimum 1
COVERAGE_CORE coverage.py's measurement core; set to ctrace in workers under --cov-context unless you set it; see Coverage core

Color precedence

Color is decided as pytest decides it: --color=yes / --color=no (also forwarded to pytest) beats every variable, then PY_COLORS, then NO_COLOR, then FORCE_COLOR, then whether stdout is a terminal.

Cache location

.rstest_cache sits at the pytest rootdir, so a run from a subdirectory shares the project's cache. It holds durations, flakes, the run history, the coverage index, the last-green baseline, the green snapshot (green_env.json) and replay journals (replay/). At a monorepo root with RSTEST_CACHE set, each project gets <RSTEST_CACHE>/<slug> (a relative value resolves against the monorepo root); unset, each project keeps its own <project>/.rstest_cache.

Remote cache token

rstest removes RSTEST_CACHE_REMOTE_TOKEN from the environment it gives test processes (workers, and the pytest baseline of rstest try), so it doesn't show up in os.environ. That is defense in depth, not a secret boundary: the rstest process itself still holds it, and a test running as the same user can read another process's environment (/proc/<pid>/environ on Linux). Give jobs that run untrusted code a read-only token.

Interpreter-probe cache

RSTEST_CACHE_DIR sets where <dir>/rstest/interp-probes-v1.json lives; that file speeds up repeated --python version resolution. It does not relocate .rstest_cache/ (durations, flakes); use RSTEST_CACHE for that. It defaults to $XDG_CACHE_HOME (or ~/.cache) on Unix and %LOCALAPPDATA% on Windows; if none resolve, probing just isn't persisted.

Coverage core

Under --cov-context, rstest sets COVERAGE_CORE=ctrace in the workers unless you already set it to a non-empty value; your value wins (an empty value is overwritten). Don't set sysmon (Python 3.14's default core) for a --cov-context=test run: it keeps only the first test's context per line, which silently corrupts the coverage index behind --changed and --incremental.

Also read

Standard variables from CI systems and tools that rstest reads when present:

Variable Used for
GITHUB_BASE_REF, CI_MERGE_REQUEST_DIFF_BASE_SHA, CI_MERGE_REQUEST_TARGET_BRANCH_NAME, BUILDKITE_PULL_REQUEST_BASE_BRANCH the pull-request base for a bare --changed, probed in that order (see Selecting changed tests: CI usage)
GITHUB_STEP_SUMMARY doctor runs append their markdown report to this file on GitHub Actions
GITHUB_WORKSPACE, BUILD_SOURCESDIRECTORY the repository root that --output github / --output azure annotation paths are made relative to, when it contains the rootdir; otherwise the nearest ancestor holding .git
BUILDKITE on Buildkite (non-empty), doctor reports and flaky tests are published with buildkite-agent annotate
COV_CORE_SOURCE set by a pytest-cov parent process: coverage is measuring this run, so --fork-pool=app falls back to core (and --watch keeps the plain spawn path)
UV_PYTHON_INSTALL_DIR, XDG_DATA_HOME, APPDATA locating uv-managed interpreters during interpreter discovery (UV_PYTHON_INSTALL_DIR first, else uv's default under XDG_DATA_HOME or ~/.local/share on Unix, %APPDATA% on Windows)
XDG_CACHE_HOME, LOCALAPPDATA default base for the interpreter-probe cache (see RSTEST_CACHE_DIR)
COVERAGE_RCFILE coverage.py's config-file override. When --cov-config names no file, or names pytest-cov's default .coveragerc, rstest reads the [run] settings from this file (as coverage.py would) to decide what --cov measures. coverage.py follows the same rule when rstest combines and reports parallel coverage
HOME, USERPROFILE the home directory for rstest install-skills --user (HOME first, then USERPROFILE). HOME is also the Unix fallback base when the XDG_* variables are unset: ~/.cache for the interpreter-probe cache and ~/.local/share/uv/python for uv-managed interpreters. With neither set, probing isn't persisted and uv interpreters aren't searched
PYTHONPATH kept for the workers: rstest prepends RSTEST_WORKER_PATH (when set) and, in a source checkout, the repo's python/ directory, then appends your existing entries in order