Skip to content

Commit

Permalink
[3.12] gh-108962: Skip test_tempfile.test_flags() if not supported (G…
Browse files Browse the repository at this point in the history
…H-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 <[email protected]>
  • Loading branch information
miss-islington and vstinner authored Sep 8, 2023
1 parent 0855b2c commit b9dfe60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Lib/test/test_tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,9 +1834,25 @@ def test_modes(self):
d.cleanup()
self.assertFalse(os.path.exists(d.name))

@unittest.skipUnless(hasattr(os, 'chflags'), 'requires os.lchflags')
@unittest.skipUnless(hasattr(os, 'chflags'), 'requires os.chflags')
def test_flags(self):
flags = stat.UF_IMMUTABLE | stat.UF_NOUNLINK

# skip the test if these flags are not supported (ex: FreeBSD 13)
filename = os_helper.TESTFN
try:
open(filename, "w").close()
try:
os.chflags(filename, flags)
except OSError as exc:
# "OSError: [Errno 45] Operation not supported"
self.skipTest(f"chflags() doesn't support "
f"UF_IMMUTABLE|UF_NOUNLINK: {exc}")
else:
os.chflags(filename, 0)
finally:
os_helper.unlink(filename)

d = self.do_create(recurse=3, dirs=2, files=2)
with d:
# Change files and directories flags recursively.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Skip ``test_tempfile.test_flags()`` if ``chflags()`` fails with "OSError:
[Errno 45] Operation not supported" (ex: on FreeBSD 13). Patch by Victor
Stinner.

0 comments on commit b9dfe60

Please sign in to comment.