From 9dd28d2da941160abf0b5f54b1e7e3a7ef4465fb Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:07:54 -0700 Subject: [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 cd2ef21b076b494224985e266c5f5f8b37c66618) Co-authored-by: Victor Stinner --- Lib/test/test_tempfile.py | 18 +++++++++++++++++- .../2023-09-05-23-00-09.gh-issue-108962.R4NwuU.rst | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Tests/2023-09-05-23-00-09.gh-issue-108962.R4NwuU.rst diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index ccf7ea0..2632e77 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -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. 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 index 0000000..380fb20 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-09-05-23-00-09.gh-issue-108962.R4NwuU.rst @@ -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. -- cgit v0.12