Skip to content

Fix Windows file-lock teardown in test_nodata_out_of_range_1581#1595

Merged
brendancol merged 1 commit into
mainfrom
fix-1581-test-windows-lock
May 11, 2026
Merged

Fix Windows file-lock teardown in test_nodata_out_of_range_1581#1595
brendancol merged 1 commit into
mainfrom
fix-1581-test-windows-lock

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Migrates xrspatial/geotiff/tests/test_nodata_out_of_range_1581.py from tempfile.NamedTemporaryFile(delete=False) + manual os.unlink to pytest's tmp_path fixture.
  • Fixes recurring Windows CI failures with PermissionError [WinError 32]: The process cannot access the file because it is being used by another process during teardown of the three tests that read the produced TIFF.

Root cause

open_geotiff and read_geotiff_dask route through the mmap LRU cache in xrspatial/geotiff/_reader.py. After a test returns, the mmap is parked in the idle pool with refcount 0 (the cache keeps it for reuse). Windows refuses to unlink a file while any mmap is mapped to it, so the explicit os.unlink(path) at fixture teardown raises PermissionError. Linux and macOS let you unlink mapped files, so the bug was Windows-only.

tmp_path defers cleanup to pytest's session teardown, which tolerates locked files (it logs a warning rather than failing the test). No reader-side change is needed.

Test plan

  • pytest xrspatial/geotiff/tests/test_nodata_out_of_range_1581.py — 8 passed locally
  • CI on Windows confirms the three previously-failing tests now pass:
    • test_open_geotiff_uint16_negative_nodata_does_not_raise
    • test_read_geotiff_dask_uint16_negative_nodata_compute
    • test_open_geotiff_uint16_in_range_nodata_still_masks

Related

Unblocks the Windows CI matrix for PR #1586 and any future PR touching this test file.

The tests in test_nodata_out_of_range_1581.py wrote via
tempfile.NamedTemporaryFile(delete=False) and unlinked manually at
teardown. On Windows that fails with PermissionError [WinError 32]:
open_geotiff and read_geotiff_dask leave the file's mmap alive in the
reader's LRU cache, and Windows refuses to delete an mapped file.

tmp_path leaves cleanup to pytest, which tolerates locked files at
session teardown.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 11, 2026
@brendancol brendancol merged commit 6700332 into main May 11, 2026
11 of 12 checks passed
@brendancol brendancol deleted the fix-1581-test-windows-lock branch May 15, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant