From 78980f768cabad6440ffb810e36df34679dc2a94 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 8 Jul 2025 19:14:40 +0200 Subject: [PATCH 1/3] gh-136156: Skip test_tempfile.test_link_tmpfile() on Android --- Lib/test/test_tempfile.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 36151b016ea35b..40bd8abb8ccf35 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -1611,9 +1611,13 @@ def test_link_tmpfile(self): tmp.flush() fd = tmp.fileno() - os.link(f'/proc/self/fd/{fd}', - filename, - follow_symlinks=True) + try: + os.link(f'/proc/self/fd/{fd}', + filename, + follow_symlinks=True) + except PermissionError as exc: + # gh-136156: link() fails with PermissionError on Android + self.skipTest(str(exc)) with open(filename) as fp: self.assertEqual(fp.read(), "hello") From 00cb44462f48940686782007bdd0994c9e9c62c4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 8 Jul 2025 19:26:31 +0200 Subject: [PATCH 2/3] Add more context in the skip message --- Lib/test/test_tempfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 40bd8abb8ccf35..3a28e6c80ed1dd 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -1617,7 +1617,8 @@ def test_link_tmpfile(self): follow_symlinks=True) except PermissionError as exc: # gh-136156: link() fails with PermissionError on Android - self.skipTest(str(exc)) + self.skipTest(f"os.link: {exc!r}") + with open(filename) as fp: self.assertEqual(fp.read(), "hello") From c21182dbf133921477138cb378a8006d191eaa0c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 9 Jul 2025 16:57:03 +0200 Subject: [PATCH 3/3] Use @os_helper.skip_unless_hardlinkv --- Lib/test/test_tempfile.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 3a28e6c80ed1dd..aeca62cf2564bc 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -1594,6 +1594,7 @@ def test_unexpected_error(self): mock_close.assert_called() self.assertEqual(os.listdir(dir), []) + @os_helper.skip_unless_hardlink @unittest.skipUnless(tempfile._O_TMPFILE_WORKS, 'need os.O_TMPFILE') @unittest.skipUnless(os.path.exists('/proc/self/fd'), 'need /proc/self/fd') @@ -1611,14 +1612,9 @@ def test_link_tmpfile(self): tmp.flush() fd = tmp.fileno() - try: - os.link(f'/proc/self/fd/{fd}', - filename, - follow_symlinks=True) - except PermissionError as exc: - # gh-136156: link() fails with PermissionError on Android - self.skipTest(f"os.link: {exc!r}") - + os.link(f'/proc/self/fd/{fd}', + filename, + follow_symlinks=True) with open(filename) as fp: self.assertEqual(fp.read(), "hello")