mirror of https://github.com/python/cpython
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).
This commit is contained in:
parent
b87263be9b
commit
cd2ef21b07
|
@ -1834,9 +1834,25 @@ class TestTemporaryDirectory(BaseTestCase):
|
||||||
d.cleanup()
|
d.cleanup()
|
||||||
self.assertFalse(os.path.exists(d.name))
|
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):
|
def test_flags(self):
|
||||||
flags = stat.UF_IMMUTABLE | stat.UF_NOUNLINK
|
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)
|
d = self.do_create(recurse=3, dirs=2, files=2)
|
||||||
with d:
|
with d:
|
||||||
# Change files and directories flags recursively.
|
# Change files and directories flags recursively.
|
||||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue