Fix Windows file-lock teardown in test_nodata_out_of_range_1581#1595
Merged
Conversation
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.
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.
Summary
xrspatial/geotiff/tests/test_nodata_out_of_range_1581.pyfromtempfile.NamedTemporaryFile(delete=False)+ manualos.unlinkto pytest'stmp_pathfixture.PermissionError [WinError 32]: The process cannot access the file because it is being used by another processduring teardown of the three tests that read the produced TIFF.Root cause
open_geotiffandread_geotiff_daskroute through the mmap LRU cache inxrspatial/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 explicitos.unlink(path)at fixture teardown raisesPermissionError. Linux and macOS let you unlink mapped files, so the bug was Windows-only.tmp_pathdefers 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 locallytest_open_geotiff_uint16_negative_nodata_does_not_raisetest_read_geotiff_dask_uint16_negative_nodata_computetest_open_geotiff_uint16_in_range_nodata_still_masksRelated
Unblocks the Windows CI matrix for PR #1586 and any future PR touching this test file.