Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd2ef21

Browse files
authored
gh-108962: Skip test_tempfile.test_flags() if not supported (#108964)
Skip test_tempfile.test_flags() if chflags() fails with "OSError: [Errno 45] Operation not supported" (ex: on FreeBSD 13).
1 parent b87263b commit cd2ef21

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
@@ -1834,9 +1834,25 @@ def test_modes(self):
18341834
d.cleanup()
18351835
self.assertFalse(os.path.exists(d.name))
18361836

1837-
@unittest.skipUnless(hasattr(os, 'chflags'), 'requires os.lchflags')
1837+
@unittest.skipUnless(hasattr(os, 'chflags'), 'requires os.chflags')
18381838
def test_flags(self):
18391839
flags = stat.UF_IMMUTABLE | stat.UF_NOUNLINK
1840+
1841+
# skip the test if these flags are not supported (ex: FreeBSD 13)
1842+
filename = os_helper.TESTFN
1843+
try:
1844+
open(filename, "w").close()
1845+
try:
1846+
os.chflags(filename, flags)
1847+
except OSError as exc:
1848+
# "OSError: [Errno 45] Operation not supported"
1849+
self.skipTest(f"chflags() doesn't support "
1850+
f"UF_IMMUTABLE|UF_NOUNLINK: {exc}")
1851+
else:
1852+
os.chflags(filename, 0)
1853+
finally:
1854+
os_helper.unlink(filename)
1855+
18401856
d = self.do_create(recurse=3, dirs=2, files=2)
18411857
with d:
18421858
# 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)