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"