Skip to content

Report JSON

rstest --report-json FILE writes a per-test outcome snapshot after the run. The schema is stable and intended for tooling (dashboards, flake tracking, result diffing).

$ rstest --report-json results.json

This page is the walkthrough: example documents, what each field means, and the version history. For generated, machine-readable JSON Schemas of the outputs that have one, see Output schemas.

Shape

{
  "meta": {
    "runner": "rstest", "schema": 5, "exitstatus": 0,
    "counts": { "passed": 12, "failed": 0, "errors": 0, "skipped": 1,
                "xfailed": 0, "xpassed": 0, "flaky": 0, "quarantined": 0,
                "collect_errors": 0 },
    "duration_seconds": 4.21, "started_at_epoch": 1765500000,
    "workers": 8, "argv": ["rstest", "-n", "8"]
  },
  "collect_errors": [],
  "tests": {
    "tests/test_login.py::test_ok": {
      "setup": "passed",
      "call": "passed",
      "teardown": "passed",
      "duration": 0.0123,
      "lineno": 14
    },
    "tests/test_login.py::test_skipped_one": {
      "setup": "skipped",
      "teardown": "passed",
      "skip_reason": "Skipped: needs postgres"
    }
  }
}

meta.counts follows pytest's terminal accounting, which counts phase reports rather than tests: a test that passes and then errors in teardown adds 1 to passed and 1 to errors, and an xfail test's teardown error adds to xfailed. The keys can therefore sum to more than the number of tests.

meta.argv is the full command line

meta.argv records rstest's command line verbatim. A credential on it, such as a password in a --cache-remote https://user:pass@host/... URL, lands in the report and in every CI artifact that uploads it. Pass secrets through the environment instead (RSTEST_CACHE_REMOTE, RSTEST_CACHE_REMOTE_TOKEN), which the report does not record.

Per-test fields (absent when not applicable):

Field Type Meaning
setup / call / teardown "passed" / "failed" / "skipped" phase outcomes; a test skipped at setup has no call. An xfail test records "call": "skipped" with wasxfail: true. A test with a failed subtest has call: "failed"
subtests_failed int failed subtests (unittest subTest, the subtests fixture). Each counts once in meta.counts.failed, as in pytest's summary; the test itself counts by its own outcome (pytest leaves a unittest test passed and fails a subtests fixture test). Omitted when 0
duration seconds call-phase wall time, 4 decimal places
cpu seconds call-phase CPU time (process_time plus child processes the test waited for), 4 decimals. duration ≫ cpu ⇒ wait-bound (sleep/IO). Only present when measured: a --doctor run or a live-stream run (--output json / --stream-json); omitted on a plain run so the snapshot stays comparable to the pytest baseline
lineno int 0-based source line of the test (pytest report.location; add 1 for an editor line or rstest explain's 1-based source_line); omitted when pytest reports none. The file is the nodeid's path
wasxfail true the test was an expected failure (xfail/xpass)
skip_reason string pytest's skip message, first 200 chars; it keeps pytest's Skipped: prefix (@pytest.mark.skip(reason="needs postgres") gives "Skipped: needs postgres")
flaky true passed only after --reruns or @pytest.mark.flaky retries. Counted in meta.counts.flaky, not also in passed
quarantined true failed, but matched the --quarantine list or the auto-quarantine set: non-fatal
longrepr string failure text (assertion repr / traceback) as pytest prints it in the --tb style in effect (under --tb=line its last line is the path:line: message crash line), failures only, capped at 20,000 bytes (cut on a UTF-8 character boundary)
crashed true the failure was fabricated by the orchestrator: worker crash, --worker-timeout kill, or the test that was running when SIGINT/SIGTERM stopped the run; pytest never reported it. longrepr says which
worker "gw2" worker that produced the final outcome (pool runs only)
cached true not executed this run: skipped by --incremental because it passed last run and its covered source is unchanged. Counts as passed. A cached entry carries only "call": "passed", "cached": true and, when the prior run recorded it, lineno (no setup, teardown or duration)

meta.schema is the document version, currently 5. History: 1 was the unversioned original (phases, duration, wasxfail, skip_reason, flaky, worker); 2 added longrepr and crashed plus the version field itself; 3 added the envelope, counts (pytest-accounting outcome totals, all keys always present, the same numbers as the terminal summary line, which like pytest's adds collect_errors into its errors and also shows the deselected count: never re-derive them by walking tests), duration_seconds, started_at_epoch, workers, and argv; 4 added per-test lineno; 5 added per-test quarantined and the quarantined counts key. Parse it: incompatible changes will bump it.

The per-test cpu field arrived without a schema bump: it is conditional (present only on --doctor / live-stream runs), so a plain run's document shape is unchanged. Treat it as an added optional field. The per-test cached field is the same kind of addition: present only on --incremental runs, no bump. So is subtests_failed: present only on a test with a failed subtest.

Boolean fields (wasxfail, flaky, quarantined, crashed, cached) are omitted when false, never written as false. Read a missing key as false.

The meta.shard block is the same kind of conditional, no-bump addition: present only on a --shard K/N run (full collection, not --collect lazy). It carries { "k", "n", "collection_hash", "collection_size" } where collection_hash is the sha256 of the full ordered nodeid list and collection_size its length, identical across every shard of one run. Under --budget it also lists budget_skipped, the tests in this shard's bucket the budget left out (absent when none). rstest shard-verify consumes it to prove a shard matrix covered the whole suite.

meta.warm_template is another conditional, no-bump addition: present only when a --fork-pool=app template imported the app for this run's workers (the default under --watch). modules is how many modules it imported before forking, denied how many are on the warm manifest's deny list (imported per worker instead), and import_seconds how long its imports took. Under --watch the template is built once and reused, so the object appears on the cycle that built it:

"warm_template": {"denied": 4, "import_seconds": 1.83, "modules": 312}

collect_errors lists the file paths of collectors that failed outright. collect_error_reprs maps each of those paths to its traceback, and is absent when there are none. It also carries errors that escaped the whole test session, listed as <session: ExceptionType>: for example a warning raised at session end under filterwarnings = error, which exits 1 even when every test passed.

failure_groups is present when two or more failed tests share a cause (see Failures by cause), largest group first: { "exception", "message", "at", "count", "nodeids" }, where at is the shared project frame as path:line (or null when every frame was outside the project) and message is the first member's. A run with no shared cause leaves the key out, so earlier consumers see the same document as before.

At a monorepo root, the document is the merged result of every project: test keys are root-relative nodeids (libs/core/tests/test_x.py::test_y), collect-error paths are prefixed the same way, and meta.projects maps each project to {"exitstatus": N, "counts": {...}} or {"skipped": true}; meta.counts holds the grand totals across projects. meta.projects is added by the merge and is not in the generated Run report schema. It carries the same meta.schema as a single-project document. (rstest 0.7.0 stamped merged documents "schema": 4 although they carried schema-5 fields; treat those as schema 5.)

For suite-health data (timings analysis, wait-bound tests, fixture costs) use --doctor-json instead; the two schemas are independent.

Discovery JSON

Pairing --report-json with --collect-only (or --co) collects the suite without running it and writes a discovery document: the machine-readable surface editor/CI integrations consume to build a test tree, instead of parsing pytest's text output.

$ rstest --collect-only --report-json discovery.json
{
  "meta": {
    "runner": "rstest", "kind": "discovery", "schema": 1,
    "count": 3, "rootdir": "/abs/path/to/project"
  },
  "tests": [
    { "nodeid": "tests/test_login.py::test_ok",
      "file": "/abs/path/to/project/tests/test_login.py",
      "lineno": 14, "markers": [] },
    { "nodeid": "tests/test_login.py::test_slow",
      "file": "/abs/path/to/project/tests/test_login.py",
      "lineno": 22, "markers": ["serial"] },
    { "nodeid": "tests/test_api.py::test_q[1]",
      "file": "/abs/path/to/project/tests/test_api.py",
      "lineno": 9, "markers": ["parametrize", "xdist_group"] }
  ],
  "collect_errors": [
    { "path": "tests/test_broken.py", "longrepr": "ImportError: ..." }
  ]
}

This is a distinct document from the run snapshot above: its own meta.kind ("discovery") and meta.schema (currently 1).

Per-test fields:

Field Type Meaning
nodeid string pytest nodeid (parametrized variants are separate entries)
file string absolute path to the test file (editor-ready URI); empty when pytest reports no location
lineno int / null 0-based source line; null when pytest reports none
markers string[] every pytest marker name on the item: own and inherited from class/module (pytestmark), sorted and de-duplicated. Includes serial, flaky, skip, xfail, parametrize, xdist_group, and any custom marks. Names only (no args/reason)

collect_errors lists files that failed to import/collect, with their longrepr. The process exit code matches pytest's collection result (2 when any collector errored).

Discovery needs a single pytest session, so at a monorepo root it is refused (each project has its own rootdir and config: one session can't represent them). Run it once per project instead, with the working directory set to that project:

$ cd libs/core && rstest --collect-only --report-json discovery.json

meta.rootdir is then that project's root, and file paths are absolute within it.

Streaming JSON

rstest --output json produces a third, separate shape: a live newline-delimited JSON stream on stdout, one object per line, emitted as the run proceeds rather than a single document written at the end.

$ rstest --output json

It's built for editors and CI tooling that update a test tree incrementally. See --output for the flag.

The same stream is also available as a side channel via --stream-json FILE: identical testreport / sessionfinish events, written to FILE (a regular file or a fifo) instead of stdout, so the human terminal output is preserved. Use --output json when the process's stdout is the machine stream; use --stream-json when you want normal output on the terminal and the events on a separate stream at the same time (e.g. a VS Code extension showing a test terminal while updating the Test Explorer).

Three event kinds, discriminated by event:

{"event": "testreport", "nodeid": "tests/test_api.py::test_get", "when": "call", "outcome": "passed", "duration": 0.0123, "wasxfail": false, "lineno": 41, "worker": "gw2"}
{"event": "collecterror", "path": "tests/test_bad.py", "longrepr": "ImportError while importing test module ..."}
{"event": "sessionfinish", "exitstatus": 1, "duration": 4.21, "counts": {"passed": 28, "failed": 1, "errors": 0, "skipped": 0, "xfailed": 0, "xpassed": 0, "flaky": 0, "quarantined": 0, "collect_errors": 0}}

One testreport is emitted per phase (setup, call, teardown), so a single test produces up to three lines, mirroring pytest's own report granularity. Fields:

Field Type Meaning
event string always "testreport"
nodeid string pytest nodeid
when string phase: setup / call / teardown
outcome string passed / failed / skipped
duration float phase duration in seconds (rounded to 1e-4)
wasxfail bool the outcome was an expected failure / unexpected pass
lineno int 0-based source line; omitted when pytest reports none
cpu float call-phase CPU seconds (process_time plus child processes the test waited for); on the call report only. duration ≫ cpu ⇒ wait-bound (sleep/IO). Present whenever a stream is active, including at -n 0
worker string gwN: pool runs only; absent under -n 0
longrepr string failure traceback; present only on failed
sections array captured output: [{name, text}] (e.g. Captured stdout call), each tail-capped at 20 000 chars. Present on failures, and on every report when this stream is active (so passing-test output shows too); omitted when a report captured nothing

A collecterror is emitted when a module fails to import / collect during the run, so a tree can mark the file red live rather than waiting for sessionfinish:

Field Type Meaning
event string always "collecterror"
path string the failing collector: rootdir-relative file or nodeid
longrepr string the collection traceback

Under full collection every worker collects the whole suite, but the same file's collecterror is emitted once, like its entry in collect_errors and meta.counts.collect_errors.

The stream closes with exactly one sessionfinish:

Field Type Meaning
event string always "sessionfinish"
exitstatus int pytest-compatible exit code for the test session
duration float total wall time in seconds
counts object outcome tallies: the same keys and accounting as the snapshot's meta.counts

exitstatus reflects the test session only. Post-run gates (--fail-on-leak, --durations-regress, --doctor-fail-on, --cov-fail-under, --cov-diff-fail-under; see Exit codes) run after this envelope is streamed, so they cannot change it: a green session that fails a gate still reports "exitstatus": 0 here while the process exits non-zero. Key CI success off the process exit code, not this field.

Unlike the snapshot and discovery documents, the stream is not versioned (no schema field) and should be treated as experimental: consume by event kind and tolerate added fields. No banner, footer, or human summary is interleaved, so every line parses on its own.

Doctor JSON

rstest --doctor-json FILE writes the --doctor suite-health analysis as a single versioned document: the machine-readable surface for CI trending (diff two runs to catch new long poles, fixture-cost growth, or wait-time regressions; a ready-made recipe is in the Suite diagnostics).

$ rstest --doctor-json doctor.json

It is a separate document from the run snapshot above; combine with --doctor to also print the human report.

{
  "schema": 3,
  "rstest_version": "0.12.0",
  "workers": 8,
  "wall_seconds": 68.4,
  "startup_seconds": 0.6,
  "fork_prewarm": false,
  "tests": 2048,
  "test_time_seconds": 412.9,
  "cpu_time_seconds": 120.3,
  "wait_bound": {
    "wait_seconds": 292.6,
    "wait_pct": 70.8,
    "tests": [
      { "nodeid": "tests/test_api.py::test_slow_remote", "duration": 4.81, "wait": 4.72 }
    ]
  },
  "parallel_floor": {
    "longest_seconds": 84.1,
    "ideal_share_seconds": 51.6,
    "gate_tests": [
      { "nodeid": "tests/test_e2e.py::test_full_flow", "duration": 84.1 }
    ]
  },
  "parallel_efficiency": {
    "realized_speedup": 6.04,
    "ideal_speedup": 8,
    "efficiency_pct": 75.4,
    "workers_busy": [
      { "worker": "gw3", "busy_seconds": 68.0, "tests": 240 },
      { "worker": "gw1", "busy_seconds": 41.2, "tests": 268 }
    ],
    "imbalance_pct": 39.4,
    "long_pole_seconds": 84.1
  },
  "fixtures": [
    { "name": "pg_database", "scope": "session", "count": 8, "total_seconds": 31.2 },
    { "name": "feature_flags", "scope": "function", "count": 206, "total_seconds": 4.3,
      "constant": true, "projected_saving_seconds": 0.52 }
  ],
  "slowest_files": [
    { "file": "tests/test_e2e.py", "total_seconds": 84.1, "pct": 20.4 }
  ],
  "coverage_waste": {
    "wasted_seconds": 18.4,
    "redundant_tests": 3,
    "tests": [
      { "nodeid": "tests/test_api.py::test_end_to_end_slow", "duration": 12.1, "covered_lines": 240, "also_covered_by": 4 }
    ]
  },
  "timeouts": {
    "suite_timeout": 3,
    "tests_judged": 1980,
    "override_count": 4,
    "overrides": [
      { "nodeid": "tests/test_e2e.py::test_full_flow", "slowest_seconds": 83.2, "runs": 41, "timeout": 250 }
    ]
  }
}

Every field, with its type and whether it is always present, is listed in the generated Doctor report field reference, which is built from the Rust type and so always matches the code. What that reference doesn't spell out:

  • schema is the document version, currently 3.
  • wall_seconds depends on the worker count: compare it across runs only at equal -n. test_time_seconds (summed per-test durations) is worker-count-independent and is the stable metric to trend. Every per-test time in the document (test_time_seconds, worker load, long pole, slowest files, wait-bound and coverage-waste durations) is the whole protocol: setup + call + teardown, so fixture time counts. The exception is timeouts and drift: their times are the call phase, read from the run history across recent runs (not this run), because the call phase is what --timeout limits. cpu_time_seconds sums CPU time over the same span (including child processes the test waited for) over the tests where it was measured; tests counts tests with a recorded call duration.
  • workers is the worker count, 1 for a single-worker run (-n 0).
  • startup_seconds is the wall time from pool spawn to every worker's first event (import + collect start), part of wall_seconds, and 0.0 on single-worker runs. --fork-pool cuts it; fork_prewarm records whether this run used it.
  • When the analysis objects are null:
    • wait_bound unless CPU time was measured and waiting is significant (wait_pct ≥ 20% and wait_seconds ≥ 1);
    • parallel_floor unless the longest test exceeds the floor threshold: the larger of the ideal per-worker share and 1 second, plus 10% slack;
    • parallel_efficiency unless the run used more than one worker (workers > 1);
    • coverage_waste unless this run collected per-test coverage (--cov --cov-context=test) and at least one slow test qualified;
    • timeouts until at least one test in this run has 5 passing runs in the run history (.rstest_cache/history.msgpack). overrides is empty when every judged test fits under suite_timeout;
    • network unless a test connected outside loopback and network-allow;
    • drift unless a test in this run has 9 or more passing runs whose older, middle and newer medians rise step by step (by 1.5x and 0.2 s overall). Like timeouts, its times are call phase, from the history.
  • leaks ({nodeid, threads, fds}) is omitted when empty, and empty unless leak checking ran (--doctor or --fail-on-leak).
  • wait_bound (wall ≫ CPU: tests that wait rather than compute): wait_seconds is total test_time − cpu_time, wait_pct is that as a percent of test_time_seconds, and tests lists the worst offenders (duration ≥ 0.2s and ≥ 60% waiting) by wait, descending, at most 50.
  • parallel_floor (the tests that cap any -n): longest_seconds is the single longest test, ideal_share_seconds is test_time_seconds / workers (the per-worker floor if work split perfectly), and gate_tests lists the tests among the 10 longest that run longer than the larger of that share and 1 second, plus 10% slack.
  • parallel_efficiency (realized speedup against the worker budget): realized_speedup is test_time_seconds / wall_seconds. Each worker runs one test at a time, so it stays at or below ideal_speedup (the worker count) and efficiency_pct at or below 100%; a wait-bound suite run with -n above the core count can realize more than the core count. workers_busy covers every worker, busiest first (the terminal report shows at most 8; the JSON is not truncated); tests with no recorded worker are bucketed as "serial". imbalance_pct is 100 × (busiest − idlest) / busiest. long_pole_seconds is the slowest single test, the hard floor no worker count beats.
  • fixtures[]: fixture name, pytest scope, setup count and summed setup time, slowest first, at most 50. constant (present only when true) marks a function-scoped fixture that returned the same immutable builtin value on every call in every worker, a scope-promotion candidate; projected_saving_seconds (present only when non-zero) is the wall time promoting it to session scope would save: the largest per-worker-session (calls − 1) × mean setup. constant also requires some worker session to have run it at least twice, and is never set for fixtures with per-test teardown or narrower-scoped dependencies, for parametrize arguments, or for failed or skipped setups (see Suite diagnostics).
  • slowest_files[]: per-file totals, slowest first, at most 20; pct is the file's share of test_time_seconds.
  • coverage_waste (slow tests that cover no line another test doesn't also cover, so they are safe to delete or merge): wasted_seconds sums every redundant slow test, not just the shown ones; tests shows the slowest of them, worst first, at most 20.

schema history: 1 was the original (wall_seconds, test_time_seconds, cpu_time_seconds, wait_bound, parallel_floor, fixtures, slowest_files); 2 added the parallel_efficiency object; 3 added the per-fixture constant / projected_saving_seconds scope-promotion fields, the coverage_waste object, and the startup_seconds / fork_prewarm fields. The leaks array is a conditional, no-bump addition (omitted when empty); read a missing key as no leaks. The timeouts, drift and network objects are no-bump additions too: a current document always carries them (null when they don't apply), and an older one lacks them; read a missing key as null.

schema aside, all times are raw seconds (no rounding): round in your consumer. Increment-only: incompatible changes bump schema.

Migrate-check JSON

rstest migrate-check --migrate-check-json FILE writes the migrate-check parallel-readiness report as a single versioned document: the machine-readable surface for CI gating (fail the build when a new parallel-unsafe test appears) and for tooling that renders the findings.

$ rstest migrate-check --migrate-check-json migrate.json

It is a separate document from the run snapshot. The flag is only read by the migrate-check subcommand, which prints its human report as well; passed to a normal run, it does nothing.

{
  "meta": { "runner": "rstest", "kind": "migrate-check", "schema": 1 },
  "ready": false,
  "tests_collected": 4309,
  "will_bail_count": 64,
  "unstable_ids": [
    {
      "site": "tests/test_complex.py::test_complex_with_special_methods",
      "kinds": { "address": 12 },
      "will_bail": true,
      "allowed": false,
      "sample": "<ComplexWithIndex object at 0x10ae4e660>-(10+0j)",
      "fix": "give this parametrize a stable ids= (e.g. ids=[c.name for c in cases])"
    }
  ],
  "parallel": {
    "ran": true,
    "ready": false,
    "preexisting": 404,
    "findings": [
      {
        "nodeid": "tests/test_callback_warning.py::test_warns_when_unsupported",
        "verdict": "ISOLATION / CO-LOCATION",
        "why": "passes serial, fails under both load and loadfile — co-located state leak",
        "fix": "reset the leaked global state per test; stopgap @pytest.mark.serial",
        "allowed": false,
        "polluter": { "kind": "other_file", "file": "tests/test_other.py" }
      }
    ]
  }
}

Top-level fields:

Field Type Meaning
meta object {runner, kind, schema}; schema is the document version, currently 1
ready bool true only when no id forces -n 0 (WILL-bail) and the parallel phase ran with no parallel-only failures. Unstable ids that don't bail, and tests already failing at -n 0, don't clear it; allow-listing doesn't set it (an all-allow-listed run exits 0 with ready: false)
tests_collected int tests seen across the two collection passes (their union)
will_bail_count int count of ids that force -n 0: per-process unstable ids (address / uuid) plus the ids at order-unstable sites
unstable_ids array the unstable-id findings, grouped by parametrize site (see below)
parallel object / null the parallel-classification phase; null when it was skipped (a WILL-bail id stopped the run before it)

unstable_ids[]: one entry per parametrize site with run-to-run unstable ids:

Field Type Meaning
site string the nodeid up to the […] parametrize segment
kinds object count of each instability class at this site: address, uuid, time, other, or order (same ids, different order between the two collections)
will_bail bool true if any id here is per-process (address/uuid) or the site is order-unstable (order), i.e. forces -n 0
allowed bool matched a --migrate-allow substring (excluded from the gate)
sample string a sample unstable param value from this site
fix string the upstream fix (give the parametrize a stable ids=)

parallel ({"ran": false} alone when the phase started but captured no outcomes):

Field Type Meaning
ran bool whether the parallel classification actually executed (one worker per test file, up to your logical cores, at least 2; not -n auto)
ready bool true when no test failed only in parallel (tests already failing at -n 0 don't count)
preexisting int tests already failing at -n 0 (a pre-existing bug, not a migration concern)
findings array the classified parallel-only failures (see below)

parallel.findings[]:

Field Type Meaning
nodeid string the failing test
verdict string INTRINSIC FLAKE / ORDER DEPENDENCY / CONCURRENT RACE / WALL-CLOCK / LOAD-SENSITIVE / ISOLATION / CO-LOCATION / INCONCLUSIVE
why string the evidence behind the verdict
fix string the recommended fix plus rstest stopgap
allowed bool matched a --migrate-allow substring (excluded from the gate)
polluter object / null for ORDER DEPENDENCY / ISOLATION / CO-LOCATION: {kind: "other_file", file}, {kind: "same_file", file}, or {kind: "not_reproducible"}; null otherwise

The exit code is not in the document; read it from the process: 1 when any non-allow-listed WILL-bail id or parallel finding exists, 2 when the parallel pass produced no outcomes (parallel is {"ran": false}) or rstest hit an error. Increment-only: incompatible changes bump meta.schema.

Audit, bisect, explain, flaky, since-green and xdist-removal-check JSON

These six documents have no walkthrough on this page. Their field references and JSON Schemas are generated from the code on Output schemas, and each subcommand's page covers when it writes the document and what its exit codes mean:

Document Written by Exit codes
audit rstest audit --audit-json FILE audit
bisect rstest bisect <nodeid> --bisect-json FILE bisect
explain rstest explain <nodeid> --json (stdout) explain
flaky rstest flaky --json (stdout) flaky
since-green rstest since-green --json (stdout) since-green
xdist-removal-check rstest xdist-removal-check --xdist-removal-json FILE xdist-removal-check

As with migrate-check, the exit code is not in the document. Two cases to know: bisect exits 1 and still writes a full document ("order_dependent": false, no culprits) when the victim is not order-dependent, and explain --json exits 0 with "found": false for an unknown nodeid, where the human-readable form exits 1.