fix(test): snapshot _timelapse_baselines inside the patch context to dodge CI race

test_running_observed_captures_baseline_on_restart_recovery was reading
  _timelapse_baselines.get(1) after the patch() with-block exited.
  Locally and under low parallelism this works fine — the dict still
  holds what _capture_timelapse_baseline_at_start wrote. CI under
  xdist's default load-balancing scheduling intermittently saw the
  dict empty by the time the top-level assert ran, even though the
  production code logged "Baseline at print start: 3 video files for
  printer 1" right before returning. The duplicate log line at the
  same microsecond in the captured stderr is the tell — module state
  is being re-touched between the handler completing and the test
  asserting, almost certainly via the session-scoped event_loop
  fixture in conftest.py interacting badly with the per-file
  autouse _clear_baselines teardown of a sibling test on the same
  worker.

  The test is verifying the handler captured the baseline at the
  moment it returned, so capture the relevant value at exactly
  that point — inside the with-block, immediately after the await.
  That's immune to whatever happens to the module-level dict
  afterward.
This commit is contained in:
maziggy
2026-05-24 12:30:26 +02:00
parent 02e119ea45
commit b92bdb7d09
@@ -78,7 +78,16 @@ async def test_running_observed_captures_baseline_on_restart_recovery():
},
)
assert _timelapse_baselines.get(1) == {"earlier_a.mp4", "earlier_b.mp4", "earlier_c.mp4"}, (
# Snapshot the dict state immediately after the handler returns —
# don't rely on _timelapse_baselines surviving outside the patches.
# CI intermittently saw the dict empty by the time a later top-level
# assert ran (likely an xdist-parallel teardown race on the session-
# scoped event_loop fixture in conftest.py). Capturing the value here
# is what the test actually wants to verify anyway: the handler set
# the baseline at the moment it returned.
captured = _timelapse_baselines.get(1)
assert captured == {"earlier_a.mp4", "earlier_b.mp4", "earlier_c.mp4"}, (
"restart-recovery handler must capture the printer's existing-videos "
"baseline so the completion-time scan can set-diff to find the new file"
)