Repository navigation
grass.temporal: Use an explicit env in the gui_support test session - #7732
Merged
Merged
Conversation
The module-scoped fixture created its sessions with gs.setup.init() without env, which sets the session up in the global os.environ. init() prepends the GRASS executable paths to PATH on every call and never removes them again, so PATH kept growing for the rest of the pytest process, and later tests which copy os.environ inherited it. On Windows this made r.coin fail on main since OSGeo#7714 was merged: r.coin runs r.stats in a subprocess, and cmd.exe could no longer resolve it on the inherited PATH, so r.coin reported an empty table. Create the sessions with env=os.environ.copy() instead. tgis reads the session from os.environ, so mirror the second session there with monkeypatch, which restores the environment once the module is done. This is what test_project_without_temporal_database in the same file already does. The ultimate fix is for tgis to accept env, which would remove the need for the mirroring. Document the rule and the tgis exception in AGENTS.md. The investigation of the CI failure and this patch were done with the assistance of Claude Code.
wenzeslaus
commented
Jul 16, 2026
ninsbl
approved these changes
Jul 16, 2026
wenzeslaus
enabled auto-merge (squash)
July 16, 2026 15:12
Member
Author
|
Issues opened for the individual causes found in this investigation:
Any of these would help to avoid the issue this PR solves, but each makes sense separately, but I can't create PRs for all at this point. |
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.
The temporal tests needs separate environment like all the other tests, but env can't be explicitly passes as for the rest of the API, so this uses pytest's monkeypatch to work around that.
Details
Problem
The fixture added in #7714 creates its sessions with
gs.setup.init(...)withoutenv, which sets the session up in the globalos.environ.init()callssetup_runtime_env()unconditionally, which prepends the GRASS executable paths toPATHand never removes them again, so every such call growsPATHpermanently for the rest of the pytest process (measured: +404 characters per call). pytest runs everything in one process, so later tests which copyos.environinherit it.Fix
Create the sessions with
env=os.environ.copy().tgisreads the session fromos.environand cannot take anenv, so the second session is mirrored there withmonkeypatch, which restores the environment when the module finishes.test_project_without_temporal_databasein the same file already does this, so this only makes the fixture consistent with it.AGENTS.mdgets the rule and thetgisexception documented in its Writing Tests section.What it broke
r.coin has been failing in the OSGeo4W (Windows) CI on
mainsince #7714 was merged, with nothing in r.coin changed. It is not flaky: every run whose base contains c7fc4ea fails, every run without it passes (20 runs checked). r.coin runs r.stats in a subprocess rather than computing the table itself, and on the inheritedPATHcmd.execould no longer resolve it:so r.coin printed an empty table and the test saw
[(0, 1, 0), (0, 2, 0), (0, 3, 0)]. It is the only tested tool which runs another tool, which is why it alone is affected.Follow-ups, not in this PR
grass.temporalto acceptenv; the mirroring here could then go away.gs.setup.init()re-prepending toPATHon every call is worth fixing on its own, since it is what turns one env-lessinit()into a process-wide leak. 18 other env-less call sites remain.Verification
Fixture before/after in an identical harness:
PATHgrowth goes +444 to +0. The mirroring pattern was verified against a local build:tgis.init()andtlist_grouped()still work through the mirrored environment andos.environis restored. The Windows threshold at whichcmd.exestops resolving r.stats was not reproduced locally (no Windows machine, andPATHis not printed in CI logs); CI on this PR is the check for that.The investigation and the patch were done with the assistance of Claude Code.