8000 [3.12] gh-108962: Skip test_tempfile.test_flags() if not supported (G… · python/cpython@b9dfe60 · GitHub
[go: up one dir, main page]

Skip to content

Commit b9dfe60

Browse files
[3.12] gh-108962: Skip test_tempfile.test_flags() if not supported (GH-108964) (#108967)
gh-108962: Skip test_tempfile.test_flags() if not supported (GH-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 <vstinner@python.org>
1 parent 0855b2c commit b9dfe60

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)
0