From 739a81882e3d4533de3d055d7d902fbb5bd1aee4 Mon Sep 17 00:00:00 2001 From: 0z5a Date: Mon, 2 Nov 2026 17:40:41 +0100 Subject: [PATCH] test(cuda.core): patch os only in _file_stream for the fstat atime test test_filestream_touch_atime_swallows_fstat_failure replaced os.fstat for the whole process. pytest 9.2 calls os.fstat in its fd output capture while the test runs, so the test failed under pytest 9.2.0 with the patched OSError raised from pytest's CaptureManager, although cuda.core swallowed its own fstat failure. Patch os, fstat included, only as cuda.core.utils._program_cache._file_stream sees it. Test change written with Claude Opus 5.5 and reviewed by the contributor. Signed-off-by: 0z5a --- cuda_core/tests/test_program_cache.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cuda_core/tests/test_program_cache.py b/cuda_core/tests/test_program_cache.py index c23de6d9617..95227a69ce6 100644 --- a/cuda_core/tests/test_program_cache.py +++ b/cuda_core/tests/test_program_cache.py @@ -2132,6 +2132,7 @@ def _failing_open(path, flags, *args, **kwargs): assert not utime_calls, "os.utime must not run after os.open fails" +@pytest.mark.human_reviewed def test_filestream_touch_atime_swallows_fstat_failure(tmp_path, monkeypatch): """The best-effort atime bump swallows an ``os.fstat`` failure after the fd was opened: the read still returns the cached bytes, closes the fd, and @@ -2171,10 +2172,21 @@ def _failing_fstat(fd): raise OSError("fstat refused") utime_calls = [] - monkeypatch.setattr(_os, "open", _recording_open) - monkeypatch.setattr(_os, "close", _recording_close) - monkeypatch.setattr(_os, "fstat", _failing_fstat) - monkeypatch.setattr(_os, "utime", lambda *a, **k: utime_calls.append((a, k))) + + # Patch os only as _file_stream sees it: pytest's own output capture also calls os.fstat. + class _PatchedOs: + open = staticmethod(_recording_open) + close = staticmethod(_recording_close) + fstat = staticmethod(_failing_fstat) + + @staticmethod + def utime(*a, **k): + utime_calls.append((a, k)) + + def __getattr__(self, name): + return getattr(_os, name) + + monkeypatch.setattr(_program_cache._file_stream, "os", _PatchedOs()) assert cache[b"k"] == b"v" assert fstat_calls, "the atime bump should have attempted os.fstat"