From 0ae85d9ef00d8e3b93875d95076286e08e6f1db0 Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Fri, 15 May 2026 09:52:14 -0700 Subject: [PATCH] geotiff: fix test_writer_returns_are_not_none on Windows (#1938) The post-merge test added in #1938 used ``tempfile.TemporaryDirectory`` for its setup. ``write_vrt`` reads each source through the module-level ``_MmapCache`` in ``_reader.py`` (kept around so repeated reads of the same file are cheap), so the file handle and mmap of ``src.tif`` stay open past ``_FileSource.close()``. On Windows that cached handle blocks ``os.unlink`` with ``WinError 32`` and the synchronous tempdir teardown fails before the test can return, breaking pytest on every Windows job. Switch the test to the ``tmp_path`` fixture used by the other seven tests in this file. ``tmp_path`` defers cleanup to pytest's session-end sweep, which tolerates the still-open handle. The library behaviour is intentional and unchanged. --- .../tests/test_writer_return_path_1938.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/xrspatial/geotiff/tests/test_writer_return_path_1938.py b/xrspatial/geotiff/tests/test_writer_return_path_1938.py index f364f4633..4dc9b328d 100644 --- a/xrspatial/geotiff/tests/test_writer_return_path_1938.py +++ b/xrspatial/geotiff/tests/test_writer_return_path_1938.py @@ -22,7 +22,6 @@ import inspect import io import os -import tempfile import numpy as np import pytest @@ -169,14 +168,23 @@ def test_writer_signatures_declare_path_return(): ) -def test_writer_returns_are_not_none(): +def test_writer_returns_are_not_none(tmp_path): """None of the public writers may go back to returning ``None``.""" + # Use the ``tmp_path`` fixture (not ``tempfile.TemporaryDirectory``) + # because ``write_vrt`` reads each source through the module-level + # ``_MmapCache`` in ``_reader.py``, which keeps the file handle and + # mmap of ``src.tif`` open after ``_FileSource.close()`` so repeated + # reads of the same file stay cheap. On Windows that cached handle + # blocks ``os.unlink`` (WinError 32), so a synchronous + # ``TemporaryDirectory`` teardown raises before the test returns. + # ``tmp_path`` defers cleanup to pytest's session-end sweep, which + # tolerates the still-open handle the same way the other tests in + # this file already do. da = _small_da() - with tempfile.TemporaryDirectory() as td: - out = os.path.join(td, "out.tif") - rv = to_geotiff(da, out) - assert rv is not None - src = os.path.join(td, "src.tif") - to_geotiff(da, src) - vrt_rv = write_vrt(os.path.join(td, "m.vrt"), [src]) - assert vrt_rv is not None + out = str(tmp_path / "out.tif") + rv = to_geotiff(da, out) + assert rv is not None + src = str(tmp_path / "src.tif") + to_geotiff(da, src) + vrt_rv = write_vrt(str(tmp_path / "m.vrt"), [src]) + assert vrt_rv is not None