https://github.com/python/cpython/commit/ac8759f5549c4d69aab7bdaf26a1d51a2443d1f6
commit: ac8759f5549c4d69aab7bdaf26a1d51a2443d1f6
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-11-12T19:02:28Z
summary:

[3.15] gh-126253: Ignore unknown Windows file attributes in test_os (GH-156305) 
(#161899)

gh-126253: Ignore unknown Windows file attributes in test_os (GH-156305)
(cherry picked from commit 20876589722925438ed2988c3f2a9d8869b20e9e)

Co-authored-by: 万彬宇 <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>

files:
A Misc/NEWS.d/next/Tests/2026-09-16-14-37-28.gh-issue-126253.9FOKPp.rst
M Lib/test/test_os/test_os.py

diff --git a/Lib/test/test_os/test_os.py b/Lib/test/test_os/test_os.py
index 42d6f57c2654d8..e3184240b17d38 100644
--- a/Lib/test/test_os/test_os.py
+++ b/Lib/test/test_os/test_os.py
@@ -84,6 +84,19 @@
 HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0
 
 
+def _get_file_attribute_mask():
+    mask = 0
+    for name in dir(stat):
+        if name.startswith("FILE_ATTRIBUTE_"):
+            mask |= getattr(stat, name)
+    return mask
+
+
+# gh-126253: Ignore unknown attributes, such as 0x1_000_0000
+# (Directory flag of DOS file attribute in NTFS)
+FILE_ATTRIBUTE_MASK = _get_file_attribute_mask()
+
+
 def requires_os_func(name):
     return unittest.skipUnless(hasattr(os, name), 'requires os.%s' % name)
 
@@ -4974,8 +4987,15 @@ def assert_stat_equal(self, stat1, stat2, skip_fields):
                 if attr in ("st_dev", "st_ino", "st_nlink", "st_ctime",
                             "st_ctime_ns"):
                     continue
-                self.assertEqual(getattr(stat1, attr),
-                                 getattr(stat2, attr),
+                value1 = getattr(stat1, attr)
+                value2 = getattr(stat2, attr)
+                if attr == "st_file_attributes":
+                    # Filesystems may report attribute bits that aren't
+                    # exposed by the stat module.
+                    value1 &= FILE_ATTRIBUTE_MASK
+                    value2 &= FILE_ATTRIBUTE_MASK
+                self.assertEqual(value1,
+                                 value2,
                                  (stat1, stat2, attr))
         else:
             self.assertEqual(stat1, stat2)
diff --git 
a/Misc/NEWS.d/next/Tests/2026-09-16-14-37-28.gh-issue-126253.9FOKPp.rst 
b/Misc/NEWS.d/next/Tests/2026-09-16-14-37-28.gh-issue-126253.9FOKPp.rst
new file mode 100644
index 00000000000000..370d822f883aa9
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2026-09-16-14-37-28.gh-issue-126253.9FOKPp.rst
@@ -0,0 +1 @@
+Fix ``test_os.test_attributes()`` on Windows NTFS: ignore unknown file 
attributes.

_______________________________________________
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