Repository navigation
r.mfilter: Avoid reopening NamedTemporaryFile on Windows in testsuite - #7878
Merged
Merged
Conversation
On Windows, a file opened via tempfile.NamedTemporaryFile() cannot be reopened by another process while the Python handle is still open, so r.mfilter failed to read the filter file created this way. Write the filter contents to a path from grass.script.tempfile() instead, which does not hold the file open, and drop the @xfail_windows markers this fix should resolve. Extracted and reworked as a standalone change from PR OSGeo#2616 (by Stefan Blumentrath / @ninsbl), which combined this fix with many other Windows-specific testsuite changes and has been open, unrebased, since 2022. Re-derived against current main rather than cherry-picked, because @ninsbl's branch predates unrelated fixes already merged to this same test file (a docstring/variance correction and other @xfail_windows additions), which a direct cherry-pick would have clobbered. This has not been verified on an actual Windows run; CI on this PR should confirm whether the @xfail_windows markers can indeed be removed. Analysis of PR OSGeo#2616 assisted by AI (Claude), including identifying this as an easily isolated, self-contained candidate for its own PR; verify before merging. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Member
Author
|
On my fork, the tests of this PR passed on windows, 351 files passing, 8 failed. The r.mfilter test passes. |
4 of 8 tasks
echoix
added a commit
to echoix/grass
that referenced
this pull request
Sep 6, 2026
test_file kept a NamedTemporaryFile handle open while passing its path to r.kappa as the output file. Windows rejects a second process opening a file while the creating process still holds the handle; POSIX allows it. Use grass.script.core.tempfile() to get an unopened path instead, the same fix already applied to r.mfilter's testsuite in OSGeo#7878, and drop the now-unneeded @xfail_windows marker. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
echoix
added a commit
to echoix/grass
that referenced
this pull request
Sep 6, 2026
test_file kept a NamedTemporaryFile handle open while passing its path to r.kappa as the output file. Windows rejects a second process opening a file while the creating process still holds the handle; POSIX allows it. Use grass.script.core.tempfile() to get an unopened path instead, the same fix already applied to r.mfilter's testsuite in OSGeo#7878, and drop the now-unneeded @xfail_windows marker. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
3 of 6 tasks
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
Extracts and reworks one self-contained change out of upstream PR
OSGeo/grass#2616 ("CI: Address
Windows specific issues in testsuite", open since 2022, 35 commits, by
Stefan Blumentrath / @ninsbl) so it can be evaluated on its own. Opened
against this fork, for testing, not upstream.
raster/r.mfilter/testsuite/test_r_mfilter.pycreates its filter-definitiontemp file with
tempfile.NamedTemporaryFile()and keeps it open (via.name) whiler.mfilteropens the same path again. On Windows this secondopen fails, because Windows does not allow reopening a file that another
handle (here, the still-open Python file object) has locked. That's why all
6 tests in this file carry
@xfail_windows. #2616 replaces this withgrass.script.tempfile(create=False), which only reserves a unique path (viag.tempfile -d) without holding it open, then writes to it directly.Motivation and context
An AI (Claude) review of #2616 in July 2026, and a second one now, flagged
this as the easiest individual piece of that PR to land as its own, minimal
PR: it is confined to one test file, has a well-understood, verifiable root
cause (the double-open bug is exactly what
@xfail_windows's own docstringdescribes), and doesn't depend on any of the PR's other, more invasive
Windows changes.
That said, #2616's own diff for this file is not usable as a straight
cherry-pick: it was branched in 2022 and never rebased, so its diff against
current
mainalso reverts changes unrelated to the tempfile fix thatlanded on
mainin the meantime — a docstring correction(
nc_spm_full_v2alphav2->nc_spm_full_v2beta1), tightenedvariancereference values, and trailing-whitespace cleanup. This PR re-implements
just the tempfile fix against current
main, so none of that unrelatedhistory gets clobbered. It also drops
filter.close()(no longer needed,since
filteris now a path string, not a file object) and the@xfail_windowsmarkers themselves, per the instruction inxfail_windows's own docstring: "Once the test is fixed and passing, removethe decorator."
I have not verified this on an actual Windows machine. If the Windows CI job
here still fails, the
@xfail_windowsmarkers should be restored, and theunderlying reasoning re-examined — the AI analysis should not be taken as
proof the fix works, only as a plausible, checkable hypothesis.
How has this been tested?
python3 -m py_compileon the changed file.ruff check --previewandruff format --diff(both clean, ruff 0.15.17to match
.pre-commit-config.yaml).this environment) — relying on this fork's CI to confirm the fix on
Windows and non-regression on Linux/macOS.
Types of changes
functionality to not work as before)
Checklist
pre-defined prefixes
of this project.
tests in this file are what the change fixes and un-xfails.)
Original fix idea from Stefan Blumentrath (@ninsbl) in
OSGeo/grass#2616, reworked here
against current
main. AI-assisted (Claude) analysis and implementation;please verify independently before relying on this, especially the removal
of the
@xfail_windowsmarkers.Generated with Claude Code (sonnet 5)