From c274a0632be9168b16758ef720eb123fab3cb974 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 9 Nov 2023 21:08:25 +0200 Subject: [PATCH 1/3] gh-111912: Run test_posix on Windows --- Lib/test/test_posix.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 9d72dba159c6be..44e73445d6a02d 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -6,9 +6,6 @@ from test.support import warnings_helper from test.support.script_helper import assert_python_ok -# Skip these tests if there is no posix module. -posix = import_helper.import_module('posix') - import errno import sys import signal @@ -22,6 +19,15 @@ import textwrap from contextlib import contextmanager +# Skip these tests if there is no posix or nt module. +try: + import posix +except ImportError: + try: + import nt as posix + except ImportError: + raise unittest.SkipTest("requires 'posix' or 'nt' module") + try: import pwd except ImportError: @@ -1009,6 +1015,7 @@ def test_environ(self): self.assertEqual(type(k), item_type) self.assertEqual(type(v), item_type) + @unittest.skipUnless(os.name == 'posix', "see bug gh-111841") def test_putenv(self): with self.assertRaises(ValueError): os.putenv('FRUIT\0VEGETABLE', 'cabbage') @@ -1220,6 +1227,7 @@ def test_sched_setaffinity(self): self.assertRaises(OSError, posix.sched_setaffinity, -1, mask) @unittest.skipIf(support.is_wasi, "No dynamic linking on WASI") + @unittest.skipUnless(os.name == 'posix', "requires Posix") def test_rtld_constants(self): # check presence of major RTLD_* constants posix.RTLD_LAZY From 081dd544a28e9c388cb1e0094e92b56842ee1d6c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 10 Nov 2023 13:00:37 +0200 Subject: [PATCH 2/3] Fail if not posix and not nt. --- Lib/test/test_posix.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 44e73445d6a02d..cd2b54997aa429 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -19,14 +19,10 @@ import textwrap from contextlib import contextmanager -# Skip these tests if there is no posix or nt module. try: import posix except ImportError: - try: - import nt as posix - except ImportError: - raise unittest.SkipTest("requires 'posix' or 'nt' module") + import nt as posix try: import pwd From 35ead8c882fa284845ec49aa82428029c0b1b8b1 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 10 Nov 2023 15:06:17 +0200 Subject: [PATCH 3/3] Update a skipping message. --- Lib/test/test_posix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index cd2b54997aa429..7440779d7200dd 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1223,7 +1223,7 @@ def test_sched_setaffinity(self): self.assertRaises(OSError, posix.sched_setaffinity, -1, mask) @unittest.skipIf(support.is_wasi, "No dynamic linking on WASI") - @unittest.skipUnless(os.name == 'posix', "requires Posix") + @unittest.skipUnless(os.name == 'posix', "POSIX-only test") def test_rtld_constants(self): # check presence of major RTLD_* constants posix.RTLD_LAZY