Skip to content

test_free_threading/test_dict.py does not guard _testcapi import #120579

@sobolevn

Description

@sobolevn

Bug report

This line is the source of this potential test failure:

from _testcapi import dict_version

» ./python.exe -m test test_free_threading -m test_dict_version -v
== CPython 3.14.0a0 (heads/main-dirty:cf49ef78f89, Jun 16 2024, 10:08:08) [Clang 15.0.0 (clang-1500.3.9.4)]
== macOS-14.4.1-arm64-arm-64bit-Mach-O little-endian
== Python build: debug
== cwd: /Users/sobolev/Desktop/cpython2/build/test_python_worker_59249æ
== CPU count: 12
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 3294917118
0:00:00 load avg: 1.67 Run 1 test sequentially in a single process
0:00:00 load avg: 1.67 [1/1] test_free_threading
Failed to import test module: test.test_free_threading.test_dict
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/loader.py", line 396, in _find_test_path
    module = self._get_module_from_name(name)
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
    ~~~~~~~~~~^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_free_threading/test_dict.py", line 11, in <module>
    from _testcapi import dict_version
ModuleNotFoundError: No module named '_testcapi'

test test_free_threading crashed -- Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/test/libregrtest/single.py", line 181, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/test/libregrtest/single.py", line 138, in _load_run_test
    regrtest_runner(result, test_func, runtests)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/test/libregrtest/single.py", line 91, in regrtest_runner
    test_result = test_func()
  File "/Users/sobolev/Desktop/cpython2/Lib/test/libregrtest/single.py", line 135, in test_func
    return run_unittest(test_mod)
  File "/Users/sobolev/Desktop/cpython2/Lib/test/libregrtest/single.py", line 35, in run_unittest
    raise Exception("errors while loading tests")
Exception: errors while loading tests

test_free_threading failed (uncaught exception)

== Tests result: FAILURE ==

1 test failed:
    test_free_threading

Total duration: 44 ms
Total tests: run=0 (filtered)
Total test files: run=1/1 (filtered) failed=1
Result: FAILURE

If you build CPython without test modules:

The following modules are *disabled* in configure script:
_ctypes_test              _testbuffer               _testcapi              
_testclinic               _testclinic_limited       _testexternalinspection
_testimportmultiple       _testinternalcapi         _testlimitedcapi       
_testmultiphase           _testsinglephase          _xxtestfuzz            
xxlimited                 xxlimited_35              xxsubtype    

The proper way is to move this import this module conditionally and skip tests that rely on it, just like other modules do.

I have a PR ready.

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions