[3.11] gh-108962: Skip test_tempfile.test_flags() if not supported (GH-108964) (#108968)

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

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2023-09-08 00:07:54 -07:00 committed by GitHub
parent effa2ecdcf
commit 9dd28d2da9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

@ -1726,9 +1726,25 @@ class TestTemporaryDirectory(BaseTestCase):
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.