https://github.com/python/cpython/commit/ae91911833552a32cc5455a08f3bd80cc07a3d83 commit: ae91911833552a32cc5455a08f3bd80cc07a3d83 branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: vstinner <[email protected]> date: 2026-11-12T19:00:26Z summary:
[3.14] gh-126253: Ignore unknown Windows file attributes in test_os (GH-156305) (#161900) 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.py diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 19674671c425f5..854334a62c50d1 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -91,6 +91,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) @@ -5335,8 +5348,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]
