Python CI and pytest

Keep the failed run, not just its traceback.

A rerun may pass, but that does not tell you what happened in the failed CI execution. Retrace records the pytest run so you can inspect that run later.

Python CI · illustrative example

The test failed once. The rerun passed.

The traceback says the total was wrong. The recording shows which rates the failed run used.

  1. 01Fails, then passes

    ci · test_order_total
    job 4127failed
    $ pytest -q
    > assert total == expected
    E assert Decimal('424.60')
    E     == Decimal('433.68')
    1 failed, 24 passed in 4.21s

    kept: ci-4127.retrace

    job 4128 · rerunpassed
    $ pytest -q --lf
    1 passed in 0.41s

    failed · then passed

    The rerun is a new execution. It can't show what the failed run did.

  2. 02Replay the failed run

    pricing.pyreplay · ci-4127.retrace
    117def convert(amount, currency):
    118 return amount * fx_cache.get(currency)

    Stops at each breakpoint in recorded order, across both threads. See below.

    two rates · original evidence

    Continue between breakpoints, or step back, and read the rate each item used.

  3. 03What the run shows

    The finding

    This order used two exchange rates.

    items 1–2 · 1.0842
    216.84
    refresh
    thread B
    items 3–4 · 1.0388
    207.76
    total
    424.60

    At one rate, the total would be 433.68.

    The source says this could happen. Only the recording shows it did.

Replay of ci-4127.retrace · both threads

Thread Acheckout requestCached ratefx_cacheThread Brate refreshrate = 1.0842rate = 1.0388
stores 1.084209:14:02.118
order starts4 × 100.00
item 1108.42
item 2108.42
stores 1.038809:14:02.131
item 3103.88
item 4103.88
total£424.60
Thread B refreshed the cached rate between item 2 and item 3. Items 3 and 4 read the new rate, so one order used two.

The problem with another rerun

A traceback identifies where a test failed. Logs can show the values someone thought to print in advance. Neither necessarily preserves the external responses, timing-related values or Python state that led to the failure. When a flaky test passes on a rerun, the original execution is already gone.

Retrace records supported Python boundary interactions and execution ordering while the test runs. The result is a .retrace artifact. During replay, the Python code executes against recorded results, allowing the original run to be inspected instead of attempting a fresh reproduction. The recording has to exist before the failure occurs.

How it fits your CI

  1. Record the test run. Run pytest through Retrace in your CI job. Each run writes a .retrace file.
  2. Keep the failed run. When a test fails, upload the .retrace file as an ordinary build artifact, alongside your logs.
  3. Investigate through cloud Replay. Provide the recording to Retrace’s cloud Replay service under the agreed pilot arrangement. Replay follows the recorded run, not a fresh execution against current services.
  4. Use VS Code on your machine. Connect to the cloud investigation through the Retrace extension. Inspect variables and the call stack, set breakpoints and step backwards from the failing assertion to the values that caused it.

Recordings can contain application data from your tests, such as captured inputs and responses. Treat them like any other sensitive build artifact and agree how they are transferred to cloud Replay.

What this changes, and what it does not

An ordinary rerun invokes the live test again; its clock, randomness, files, service responses or scheduling may differ. Replay uses the previously captured supported interactions. This helps answer which Python branch executed and what state was present in that run. It does not reconstruct a run that was never recorded, and it is not a general snapshot of every remote service or native component.

Retrace is in private preview and records on CPython 3.11–3.15 on 64-bit Linux and macOS; see the full requirements. We confirm your libraries, pytest plugins and CI setup during pilot scoping, and a trial on your own workload matters more than a general compatibility claim. Cloud Replay also needs the relevant source, dependencies and compatible execution context.

For the recording model behind this workflow, read how Python record-replay works. If you have a failing test that remains difficult to explain, discuss the investigation with the team.

Investigate a recorded Python run with us.

Bring a specific failing test or workload. We can discuss whether the current preview fits its Python version, libraries and recording boundary.

Discuss an investigation