Repository navigation
CI: Run Windows pytest suite with xdist and randomized order - #7906
Conversation
Windows CI ran pytest single-worker with a fixed test order, unlike Linux CI's pytest-xdist + needs_solo_run split. Under a fixed order, whichever test happens to run first in a given worker never changes, so an order-dependent bug that only breaks the first call to a C-based GRASS tool/library in a fresh worker process can stay hidden indefinitely. Install pytest-xdist and pytest-randomly and mirror Linux CI's parallel / needs_solo_run split so this class of bug surfaces instead of hiding. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
My original randomized order dozen reruns also included randomization of gunittest test files, but it was harder to review, so I took that out. But the good thing is, results were still stable even with a different file order. |
ninsbl
left a comment
There was a problem hiding this comment.
Just wondering, if you set: OMP_NUM_THREADS: 1 would not that in a way deactivate OpenMP tests, or are tests with nprocs>1 stil testing the OPenMP path?
We are doing this since San Michele this summer, in the other pytest-xdist test runs. The theory was that we had sometimes some tests that oversubscribed the CPU counts, or caused some kind of bottlenecks. We don’t seem to have hit as much of the sporadic failures like these. I could make an AI agent take a look and compare both. But maybe, only maybe, that’s what now makes pytest-xdist viable on Windows. The reason it wasn’t there before was more failures and longer test run times, but now it is faster |
About 20% faster pytests on Windows (considering the split), still no failures found after multiple
dozens of CI runs. (Note, there's other open PRs from me that would still need to be merged for the multiple retries validation to still hold strongly).
Description
Windows CI runs the pytest suite with a single worker and always in the same
order. Install
pytest-xdistandpytest-randomlyand mirror the parallel /needs_solo_runsplit thatpytest.ymlalready uses on Linux.Motivation and context
xdist workers are long-lived processes which handle several test files each,
so state left behind by one test can affect a later one running in the same
worker. With a single worker and a fixed order, whichever test runs first
never changes, so a failure which depends on the order has no way to show up.
Randomizing the order is what makes that kind of failure surface.
Linux CI does not use
pytest-randomlyyet; it can be added there in aseparate step if this turns out to be useful.
How has this been tested?
Windows CI on this branch, and about 30 runs of the randomized job while
looking for an order-dependent failure on Windows. The results were identical
in all of them (the same pre-existing failures, none of them related to the
order), so the randomization does not add noise to the job.
Windows CI timing: xdist vs. single worker
Compared Windows CI (
osgeo4w.yml) job data with pytest-xdist enabled (55job records from 13 runs across this investigation's branches) against
single-worker pytest (118 job records spanning 11 months of
mainhistory,2025-07-25 to 2026-06-21).
pytest step timing. xdist splits the old single step into two — a
parallel step plus a new
needs_solo_runserial step, each paying its owntest-collection overhead — compared here against the combined total:
main, before)* GitHub's job-log/step retention (roughly 3-4 months) limits step-level
"before" data to the 5 most recent
mainruns; treat as indicative, notdefinitive.
** Only the 8 full-scope, PR-triggered jobs ran both steps; 45
workflow_dispatchfishing-attempt jobs used earlier in this investigationintentionally skipped the solo/gunittest/thorough steps to isolate the
parallel step, so they only contribute to the parallel-step-alone row.
Net: the pytest step is about 20% faster with xdist, even after paying for
a second collection pass.
Whole-job duration (compile + all test steps; not expected to move,
since pytest is a small slice of it):
main, before)No meaningful difference — the job is dominated by MSYS2 setup, compiling
GRASS, and the (unchanged) single-worker gunittest thorough-test step.
Timeouts / hangs. 0 GitHub Actions
timed_outconclusions in eithergroup (0/53 xdist, 0/118 single-worker). A handful of
cancelledjobs inboth groups (3/55 xdist, 4/118 single-worker) were checked individually and
are routine
cancel-in-progresssupersession from newer pushes to the samebranch, not hangs or timeouts.
Written with the help of Claude Code, under my review.