From 2777a08ce4c23d53dc6e09d64a18eb18cfab246d Mon Sep 17 00:00:00 2001 From: Peter Marko Date: Sat, 8 Feb 2025 23:57:17 +0100 Subject: [PATCH 1/2] ctypes: correct gcc check in test In case gcc is not available, it will throw exception and test fails. So catch the exception to skip the test correctly. ====================================================================== ERROR: test_null_dlsym (test.test_ctypes.test_dlerror.TestNullDlsym.test_null_dlsym) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python3.12/test/test_ctypes/test_dlerror.py", line 61, in test_null_dlsym retcode = subprocess.call(["gcc", "--version"], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/subprocess.py", line 391, in call with Popen(*popenargs, **kwargs) as p: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/subprocess.py", line 1028, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.12/subprocess.py", line 1963, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'gcc' Signed-off-by: Peter Marko --- Lib/test/test_ctypes/test_dlerror.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_ctypes/test_dlerror.py b/Lib/test/test_ctypes/test_dlerror.py index 6bf492399cbf95..7c0e2519e38fe3 100644 --- a/Lib/test/test_ctypes/test_dlerror.py +++ b/Lib/test/test_ctypes/test_dlerror.py @@ -58,11 +58,14 @@ def test_null_dlsym(self): import subprocess import tempfile - retcode = subprocess.call(["gcc", "--version"], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL) - if retcode != 0: + try: + retcode = subprocess.call(["gcc", "--version"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + except FileNotFoundError: self.skipTest("gcc is missing") + if retcode != 0: + self.skipTest("gcc --version failed") pipe_r, pipe_w = os.pipe() self.addCleanup(os.close, pipe_r) From cbec27bd74610aa549a17ab5ba2faefb83736d9c Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 10 Feb 2025 10:17:10 +0100 Subject: [PATCH 2/2] Use OSError --- Lib/test/test_ctypes/test_dlerror.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_ctypes/test_dlerror.py b/Lib/test/test_ctypes/test_dlerror.py index 7c0e2519e38fe3..1c1b2aab3d589e 100644 --- a/Lib/test/test_ctypes/test_dlerror.py +++ b/Lib/test/test_ctypes/test_dlerror.py @@ -62,7 +62,7 @@ def test_null_dlsym(self): retcode = subprocess.call(["gcc", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - except FileNotFoundError: + except OSError: self.skipTest("gcc is missing") if retcode != 0: self.skipTest("gcc --version failed")