Skip to content

Commit 739a818

Browse files
committed
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 <[email protected]>
1 parent b6f997e commit 739a818

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎cuda_core/tests/test_program_cache.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,7 @@ def _failing_open(path, flags, *args, **kwargs):
21322132
assert not utime_calls, "os.utime must not run after os.open fails"
21332133

21342134

2135+
@pytest.mark.human_reviewed
21352136
def test_filestream_touch_atime_swallows_fstat_failure(tmp_path, monkeypatch):
21362137
"""The best-effort atime bump swallows an ``os.fstat`` failure after the fd
21372138
was opened: the read still returns the cached bytes, closes the fd, and
@@ -2171,10 +2172,21 @@ def _failing_fstat(fd):
21712172
raise OSError("fstat refused")
21722173

21732174
utime_calls = []
2174-
monkeypatch.setattr(_os, "open", _recording_open)
2175-
monkeypatch.setattr(_os, "close", _recording_close)
2176-
monkeypatch.setattr(_os, "fstat", _failing_fstat)
2177-
monkeypatch.setattr(_os, "utime", lambda *a, **k: utime_calls.append((a, k)))
2175+
2176+
# Patch os only as _file_stream sees it: pytest's own output capture also calls os.fstat.
2177+
class _PatchedOs:
2178+
open = staticmethod(_recording_open)
2179+
close = staticmethod(_recording_close)
2180+
fstat = staticmethod(_failing_fstat)
2181+
2182+
@staticmethod
2183+
def utime(*a, **k):
2184+
utime_calls.append((a, k))
2185+
2186+
def __getattr__(self, name):
2187+
return getattr(_os, name)
2188+
2189+
monkeypatch.setattr(_program_cache._file_stream, "os", _PatchedOs())
21782190

21792191
assert cache[b"k"] == b"v"
21802192
assert fstat_calls, "the atime bump should have attempted os.fstat"

0 commit comments

Comments
 (0)