Skip to content

v3.13.1 test test_ctypes/test_dlerror.py fails instead of skipping if gcc not in path #127626

Closed
@fuhsnn

Description

@fuhsnn

Bug report

Bug description:

The test use the follow logic to detect presence of gcc,

retcode = subprocess.call(["gcc", "--version"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
if retcode != 0:
self.skipTest("gcc is missing")

which appears to not recover gracefully if gcc is not in path, causing the test_ctypes test failing with the follow message:

1.356 test_signedness (test.test_ctypes.test_wintypes.WinTypesTest.test_signedness) ... ok
1.356 test_variant_bool (test.test_ctypes.test_wintypes.WinTypesTest.test_variant_bool) ... ok
1.356 
1.356 ======================================================================
1.356 ERROR: test_null_dlsym (test.test_ctypes.test_dlerror.TestNullDlsym.test_null_dlsym)
1.356 ----------------------------------------------------------------------
1.356 Traceback (most recent call last):
1.356   File "/build/cpython/Lib/test/test_ctypes/test_dlerror.py", line 64, in test_null_dlsym
1.356     retcode = subprocess.call(["gcc", "--version"],
1.356                               stdout=subprocess.DEVNULL,
1.356                               stderr=subprocess.DEVNULL)
1.356   File "/build/cpython/Lib/subprocess.py", line 395, in call
1.356     with Popen(*popenargs, **kwargs) as p:
1.356          ~~~~~^^^^^^^^^^^^^^^^^^^^^^
1.356   File "/build/cpython/Lib/subprocess.py", line 1036, in __init__
1.356     self._execute_child(args, executable, preexec_fn, close_fds,
1.356     ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.356                         pass_fds, cwd, env,
1.356                         ^^^^^^^^^^^^^^^^^^^
1.356     ...<5 lines>...
1.356                         gid, gids, uid, umask,
1.356                         ^^^^^^^^^^^^^^^^^^^^^^
1.356                         start_new_session, process_group)
1.356                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.356   File "/build/cpython/Lib/subprocess.py", line 1966, in _execute_child
1.356     raise child_exception_type(errno_num, err_msg, err_filename)
1.356 FileNotFoundError: [Errno 2] No such file or directory: 'gcc'
1.356 
1.356 ----------------------------------------------------------------------
1.356 Ran 507 tests in 0.717s
1.356 
1.356 FAILED (errors=1, skipped=33)
1.377 test test_ctypes failed
1.377 test_ctypes failed (1 error)
1.377 
1.377 == Tests result: FAILURE ==

To reproduce the above test failure, this is a Linux Dockerfile with only clang installed as $CC but no gcc in path:

FROM debian:12-slim
RUN apt-get update
RUN apt-get install -y --no-install-recommends git ca-certificates
RUN apt-get install -y --no-install-recommends make
RUN apt-get install -y --no-install-recommends clang
RUN apt-get install -y --no-install-recommends libffi-dev

WORKDIR /build/
RUN git clone --depth 1 https://github.com/python/cpython --branch v3.13.1 /build/cpython
WORKDIR /build/cpython/
RUN ./configure && make
RUN ./python -m test -v test_ctypes

Looking around, I found the adjacent test_ctypes/test_find.py used try/except OSError to wrap a similar check, I believe it could be an alternative.

try:
p = subprocess.Popen(['gcc', '--version'], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
out, _ = p.communicate()
except OSError:
raise unittest.SkipTest('gcc, needed for test, not available')

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions