Skip to content

test_ctypes.test_find seems to pass when it shouldn't #151089

Open

Description

@rossburton

Bug report

Bug description:

I have a container that has no compiler but does have ld:

$ gcc --version
-sh: gcc: command not found
$ ld --version
GNU ld (GNU Binutils) 2.46

If I run the test_ctypes tests, specifically test_find_library_with_gcc which looks like it will need gcc, it surprisingly passes:

$ python3 -mtest -v test_ctypes.test_find
== CPython 3.14.5 (main, May 10 2026, 10:21:34) [GCC 16.1.0]
== Linux-6.18.33-yocto-standard-aarch64-with-glibc2.43 little-endian
== Python build: release shared
== cwd: /tmp/test_python_worker_332æ
== CPU count: 4
== encodings: locale=ANSI_X3.4-1968 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

test_find (test.test_ctypes.test_find.FindLibraryAndroid.test_find) ... skipped 'Test only valid for Android'
test_find_nothing_with_wrong_ld_library_path (test.test_ctypes.test_find.FindLibraryEmscripten.test_find_nothing_with_wrong_ld_library_path) ... skipped 'Test only valid for Emscripten'
test_find_nothing_without_ld_library_path (test.test_ctypes.test_find.FindLibraryEmscripten.test_find_nothing_without_ld_library_path) ... skipped 'Test only valid for Emscripten'
test_find_wasm_file_with_so_extension (test.test_ctypes.test_find.FindLibraryEmscripten.test_find_wasm_file_with_so_extension) ... skipped 'Test only valid for Emscripten'
test_find_wasm_file_with_wasm_extension (test.test_ctypes.test_find.FindLibraryEmscripten.test_find_wasm_file_with_wasm_extension) ... skipped 'Test only valid for Emscripten'
test_ignore_non_wasm_file (test.test_ctypes.test_find.FindLibraryEmscripten.test_ignore_non_wasm_file) ... skipped 'Test only valid for Emscripten'
test_find_library_with_gcc (test.test_ctypes.test_find.FindLibraryLinux.test_find_library_with_gcc) ... ok
test_find_library_with_ld (test.test_ctypes.test_find.FindLibraryLinux.test_find_library_with_ld) ... ok
test_find_on_libpath (test.test_ctypes.test_find.FindLibraryLinux.test_find_on_libpath) ... skipped 'gcc, needed for test, not available'
test_gh114257 (test.test_ctypes.test_find.FindLibraryLinux.test_gh114257) ... ok
OpenGL libraries:
	 ('GL', None)
	 ('GLU', None)
	 ('gle', None)
test_gl (test.test_ctypes.test_find.Test_OpenGL_libs.test_gl) ... skipped 'lib_gl not available'
test_gle (test.test_ctypes.test_find.Test_OpenGL_libs.test_gle) ... skipped 'lib_gle not available'
test_glu (test.test_ctypes.test_find.Test_OpenGL_libs.test_glu) ... skipped 'lib_glu not available'
test_shell_injection (test.test_ctypes.test_find.Test_OpenGL_libs.test_shell_injection) ... ok

Specifically:

test_find_library_with_gcc (test.test_ctypes.test_find.FindLibraryLinux.test_find_library_with_gcc) ... ok

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Activity

  1. rossburton commented on Jun 8, 2026

    @rossburton
    ContributorAuthor

    If I remove ld then the _with_ld test fails (which I expect) but so does the _with_gcc test (which I do not):

    FAIL: test_find_library_with_gcc (test.test_ctypes.test_find.FindLibraryLinux.test_find_library_with_gcc)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib/python3.14/test/test_ctypes/test_find.py", line 122, in test_find_library_with_gcc
        self.assertNotEqual(find_library('c'), None)
        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: None == None
    
    FAIL: test_find_library_with_ld (test.test_ctypes.test_find.FindLibraryLinux.test_find_library_with_ld)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib/python3.14/test/test_ctypes/test_find.py", line 127, in test_find_library_with_ld
        self.assertNotEqual(find_library('c'), None)
        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: None == None
    
  2. rossburton commented on Jun 8, 2026

    @rossburton
    ContributorAuthor

    Ah presumably this is because find_library() does this:

                return _findSoname_ldconfig(name) or \
                       _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
    

    And the _with_gcc test mocks _findSoname_ldconfig but not _findLib_ld.

  3. rossburton commented on Jun 8, 2026

    @rossburton
    ContributorAuthor

    I have some patches, will finish and post.

  4. added 2 commits that reference this issue on Jun 10, 2026
  5. added 2 commits that reference this issue on Jun 19, 2026
  6. added 2 commits that reference this issue on Jul 20, 2026
  7. added 2 commits that reference this issue on Sep 23, 2026
  8. added 2 commits that reference this issue on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions