Repository navigation
Conversation
echoix
force-pushed
the
claude/pr-683-review-rebase-ys388b
branch
3 times, most recently
from
October 1, 2026 12:16
a057b64 to
ee27593
Compare
A fixed order of test files can hide a test which passes only because of what an earlier test did. Add a --random-order option to grass.gunittest.main to run the test files in a random order, and a --randomly-seed option to set the seed or reuse the last one with the special value last, following pytest-randomly used for the pytest suite. Random order stays opt-in. The seed is printed and stored in the reports, so that the same order can be repeated. Reports list test files in discovery order regardless of the order they ran in, so that reports of different runs can be compared. The main HTML page is still written while the tests run and rewritten in discovery order at the end. Developed with the help of an AI coding agent (Claude Code).
Use the new --random-order option of grass.gunittest.main in test_thorough.sh (Ubuntu, macOS, CMake, and Docker image tests) and test_thorough.bat (Windows). The seed is printed in the job log and stored in the test report, so an order-dependent failure can be reproduced locally with --randomly-seed. Developed with the help of an AI coding agent (Claude Code).
echoix
force-pushed
the
claude/pr-683-review-rebase-ys388b
branch
from
October 28, 2026 18:34
ee27593 to
c72a05b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This adds options to
grass.gunittest.mainto run test files in random order, and turns them on for the thorough gunittest runs in CI on all platforms.The seed option and its message follow pytest-randomly, the plugin already used for the pytest suite in CI:
--random-orderruns the test files in a random order from a new seed.--randomly-seed Nruns them in the order generated fromN.--randomly-seed lastreuses the seed of the previous run. Both imply--random-order.grass.gunittest.mainkeep the fixed order.random_seedintest_keyvalue_result.txtand a sentence inindex.html. So the order of a CI run can be reproduced locally from the log or from the downloaded report.testfiles.htmlis still written as each test file finishes, so a partial report is available during the run. At the end it is rewritten in discovery order.test_keyvalue_result.txtare sorted together.random.Random(seed).--random-orderis added totest_thorough.sh(Ubuntu, macOS, CMake, Docker image test) andtest_thorough.bat(Windows).Without the new options, behavior and report contents are unchanged.
Motivation and context
The gunittest test files always run in the same alphabetical order. A test that passes only because of what an earlier test did, or that fails only after a particular other test, stays hidden as long as the order never changes. The pytest suite in CI already runs in random order with pytest-randomly. This brings the same protection to the gunittest suite, with the seed needed to reproduce an order-dependent failure.
Each test file runs in its own process and mapset. So this can expose dependencies through state that outlives a process, such as files in shared directories or the
PERMANENTmapset, but not in-process state. Tests inside one test file still run in the usual unittest order.How has this been tested?
python/grass/gunittest/tests/grass_gunittest_random_order_test.pyrun the invoker against a minimal location and a tree oftestsuitedirectories. The tree includes names likea,a/b,a-banda.b, which sort differently as strings than in a directory walk. The tests check that:lastgrass.gunittest.mainby hand with--random-order,--randomly-seed N,--randomly-seed last(same order as the previous run; an error when the previous run was not in random order) and without the options.Results of repeated runs in random order
To check whether random order turns up order-dependent failures in the current test suite, I ran the thorough tests of this branch repeatedly in CI, each run with its own seed:
That is 129 jobs, 128 distinct seeds and about 32,000 test file runs. Each job was compared with the fixed-order results of the same job on
main.No order-dependent failure was found. The two failures not seen in fixed order were both environmental:
scripts/g.extension/testsuite/test_addons_download.pyfailed because the runner lost DNS resolution in the middle of the test (Could not resolve host: github.com). The otherg.extensiontest files passed earlier in the same run, and the file passed in the other 18 runs.scripts/v.import/testsuite/test_parallel.shgot 49 instead of 50 maps because one of the 50 imports it runs at once hitdatabase is lockedin SQLite. This is a race inside the test itself, independent of which tests ran before, and the file passed in the other 19 runs.The test files which fail on Windows in fixed order failed the same way in random order.
python/grass/pygrass/raster/testsuite/test_raster_region.py, which is already flaky in fixed order (G_malloc: unable to allocate ...), failed in 11 of 20 runs: 8 times with the same memory error and 3 times by timing out after 300 s.So random order does not add failures to CI with the current test suite, while an order dependency introduced later can surface and be reproduced from the printed seed.
Types of changes
functionality to not work as before)
Checklist
pre-defined prefixes
of this project.
Suggested squash commit message
grass.gunittest: Add option to run test files in random order
Developed with the help of an AI coding agent (Claude Code), under my review and direction.