Skip to content

Commit 9dd28d2

Browse files
[3.11] pythongh-108962: Skip test_tempfile.test_flags() if not supported (pythonGH-108964) (python#108968)
pythongh-108962: Skip test_tempfile.test_flags() if not supported (pythonGH-108964) Skip test_tempfile.test_flags() if chflags() fails with "OSError: [Errno 45] Operation not supported" (ex: on FreeBSD 13). (cherry picked from commit cd2ef21) Co-authored-by: Victor Stinner <[email protected]>
1 parent effa2ec commit 9dd28d2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Lib/test/test_tempfile.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,9 +1726,25 @@ def test_modes(self):
17261726
d.cleanup()
17271727
self.assertFalse(os.path.exists(d.name))
17281728

1729-
@unittest.skipUnless(hasattr(os, 'chflags'), 'requires os.lchflags')
1729+
@unittest.skipUnless(hasattr(os, 'chflags'), 'requires os.chflags')
17301730
def test_flags(self):
17311731
flags = stat.UF_IMMUTABLE | stat.UF_NOUNLINK
1732+
1733+
# skip the test if these flags are not supported (ex: FreeBSD 13)
1734+
filename = os_helper.TESTFN
1735+
try:
1736+
open(filename, "w").close()
1737+
try:
1738+
os.chflags(filename, flags)
1739+
except OSError as exc:
1740+
# "OSError: [Errno 45] Operation not supported"
1741+
self.skipTest(f"chflags() doesn't support "
1742+
f"UF_IMMUTABLE|UF_NOUNLINK: {exc}")
1743+
else:
1744+
os.chflags(filename, 0)
1745+
finally:
1746+
os_helper.unlink(filename)
1747+
17321748
d = self.do_create(recurse=3, dirs=2, files=2)
17331749
with d:
17341750
# Change files and directories flags recursively.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Skip ``test_tempfile.test_flags()`` if ``chflags()`` fails with "OSError:
2+
[Errno 45] Operation not supported" (ex: on FreeBSD 13). Patch by Victor
3+
Stinner.

0 commit comments

Comments
 (0)