Skip to content

grass.temporal: Use an explicit env in the gui_support test session - #7732

Merged
wenzeslaus merged 2 commits into
OSGeo:mainfrom
wenzeslaus:temporal-test-session-env
Jul 16, 2026
Merged

wenzeslaus merged 2 commits into
OSGeo:mainfrom
wenzeslaus:temporal-test-session-env

Conversation

@wenzeslaus

@wenzeslaus wenzeslaus commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

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(...) without env, which sets the session up in the global os.environ. init() calls setup_runtime_env() unconditionally, which prepends the GRASS executable paths to PATH and never removes them again, so every such call grows PATH permanently for the rest of the pytest process (measured: +404 characters per call). pytest runs everything in one process, so later tests which copy os.environ inherit it.

Fix

Create the sessions with env=os.environ.copy(). tgis reads the session from os.environ and cannot take an env, so the second session is mirrored there with monkeypatch, which restores the environment when the module finishes. test_project_without_temporal_database in the same file already does this, so this only makes the fixture consistent with it.

AGENTS.md gets the rule and the tgis exception documented in its Writing Tests section.

What it broke

r.coin has been failing in the OSGeo4W (Windows) CI on main since #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 inherited PATH cmd.exe could no longer resolve it:

'r.stats' is not recognized as an internal or external command,

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

  • The ultimate fix is for grass.temporal to accept env; the mirroring here could then go away.
  • gs.setup.init() re-prepending to PATH on every call is worth fixing on its own, since it is what turns one env-less init() into a process-wide leak. 18 other env-less call sites remain.

Verification

Fixture before/after in an identical harness: PATH growth goes +444 to +0. The mirroring pattern was verified against a local build: tgis.init() and tlist_grouped() still work through the mirrored environment and os.environ is restored. The Windows threshold at which cmd.exe stops resolving r.stats was not reproduced locally (no Windows machine, and PATH is 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.

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.
Comment thread AGENTS.md Resolved
@wenzeslaus
wenzeslaus requested a review from ninsbl July 16, 2026 12:31
@wenzeslaus

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libraries markdown Related to markdown, markdown files Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants