]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108962: Skip test_tempfile.test_flags() if not supported (#108964)
authorVictor Stinner <vstinner@python.org>
Tue, 5 Sep 2023 21:59:40 +0000 (23:59 +0200)
committerGitHub <noreply@github.com>
Tue, 5 Sep 2023 21:59:40 +0000 (21:59 +0000)
Skip test_tempfile.test_flags() if chflags() fails with "OSError:
[Errno 45] Operation not supported" (ex: on FreeBSD 13).

Lib/test/test_tempfile.py
Misc/NEWS.d/next/Tests/2023-09-05-23-00-09.gh-issue-108962.R4NwuU.rst [new file with mode: 0644]

index db08fb1c7f2a42f5bed8f5d4169891d9d7b16ff5..1673507e2f7c91f2c3ea5feadb782b441ff75291 100644 (file)
@@ -1834,9 +1834,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.
diff --git a/Misc/NEWS.d/next/Tests/2023-09-05-23-00-09.gh-issue-108962.R4NwuU.rst b/Misc/NEWS.d/next/Tests/2023-09-05-23-00-09.gh-issue-108962.R4NwuU.rst
new file mode 100644 (file)
index 0000000..380fb20
--- /dev/null
@@ -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.