https://github.com/python/cpython/commit/d1466cc00eb96320cdcd0b144ee5df76295bd4c1
commit: d1466cc00eb96320cdcd0b144ee5df76295bd4c1
branch: 3.13
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-22T07:53:39Z
summary:

[3.13] gh-154427: Check the access time in UtimeTests only if it is stored 
(GH-154428) (GH-154439)

HAMMER2 on DragonFly BSD does not store the access time and os.stat()
returns the modification time instead.  Probe the file system, like it
is already done for the timestamp resolution.
(cherry picked from commit 6f8f97fe5246837b93e6c2f3525aa9f623ecd30b)

Co-authored-by: Claude Opus 4.8 <[email protected]>

files:
M Lib/test/test_os.py

diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 9b6a05fdbe25e8..e143dc35b581c5 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -791,11 +791,18 @@ def support_subsecond(self, filename):
                 or (st.st_mtime != st[8])
                 or (st.st_ctime != st[9]))
 
+    def support_atime(self, filename):
+        # Heuristic to check if the filesystem stores the access time.
+        # Use whole seconds, to not depend on the timestamp resolution.
+        os.utime(filename, (1, 2))
+        return os.stat(filename).st_atime == 1
+
     def _test_utime(self, set_time, filename=None):
         if not filename:
             filename = self.fname
 
         support_subsecond = self.support_subsecond(filename)
+        support_atime = self.support_atime(filename)
         if support_subsecond:
             # Timestamp with a resolution of 1 microsecond (10^-6).
             #
@@ -814,12 +821,15 @@ def _test_utime(self, set_time, filename=None):
         st = os.stat(filename)
 
         if support_subsecond:
-            self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, delta=1e-6)
+            if support_atime:
+                self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, 
delta=1e-6)
             self.assertAlmostEqual(st.st_mtime, mtime_ns * 1e-9, delta=1e-6)
         else:
-            self.assertEqual(st.st_atime, atime_ns * 1e-9)
+            if support_atime:
+                self.assertEqual(st.st_atime, atime_ns * 1e-9)
             self.assertEqual(st.st_mtime, mtime_ns * 1e-9)
-        self.assertEqual(st.st_atime_ns, atime_ns)
+        if support_atime:
+            self.assertEqual(st.st_atime_ns, atime_ns)
         self.assertEqual(st.st_mtime_ns, mtime_ns)
 
     def test_utime(self):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to