3030from test .support import os_helper
3131from test .support import (
3232 STDLIB_DIR , swap_attr , swap_item , cpython_only , is_apple_mobile , is_emscripten ,
33- is_wasi , run_in_subinterp , run_in_subinterp_with_config , Py_TRACE_REFS )
33+ is_wasi , run_in_subinterp , run_in_subinterp_with_config , Py_TRACE_REFS ,
34+ requires_gil_enabled , Py_GIL_DISABLED )
3435from test .support .import_helper import (
3536 forget , make_legacy_pyc , unlink , unload , ready_to_import ,
3637 DirsOnSysPath , CleanImport , import_module )
@@ -158,6 +159,9 @@ def meth(self, _meth=meth):
158159 finally :
159160 restore__testsinglephase ()
160161 meth = cpython_only (meth )
162+ # gh-117649: free-threaded build does not currently support single-phase
163+ # init modules in subinterpreters.
164+ meth = requires_gil_enabled (meth )
161165 return unittest .skipIf (_testsinglephase is None ,
162166 'test requires _testsinglephase module' )(meth )
163167
@@ -1876,8 +1880,9 @@ def test_builtin_compat(self):
18761880 # since they still don't implement multi-phase init.
18771881 module = '_imp'
18781882 require_builtin (module )
1879- with self .subTest (f'{ module } : not strict' ):
1880- self .check_compatible_here (module , strict = False )
1883+ if not Py_GIL_DISABLED :
1884+ with self .subTest (f'{ module } : not strict' ):
1885+ self .check_compatible_here (module , strict = False )
18811886 with self .subTest (f'{ module } : strict, not fresh' ):
18821887 self .check_compatible_here (module , strict = True )
18831888
@@ -1888,8 +1893,9 @@ def test_frozen_compat(self):
18881893 require_frozen (module , skip = True )
18891894 if __import__ (module ).__spec__ .origin != 'frozen' :
18901895 raise unittest .SkipTest (f'{ module } is unexpectedly not frozen' )
1891- with self .subTest (f'{ module } : not strict' ):
1892- self .check_compatible_here (module , strict = False )
1896+ if not Py_GIL_DISABLED :
1897+ with self .subTest (f'{ module } : not strict' ):
1898+ self .check_compatible_here (module , strict = False )
18931899 with self .subTest (f'{ module } : strict, not fresh' ):
18941900 self .check_compatible_here (module , strict = True )
18951901
@@ -1908,8 +1914,9 @@ def test_single_init_extension_compat(self):
19081914 def test_multi_init_extension_compat (self ):
19091915 module = '_testmultiphase'
19101916 require_extension (module )
1911- with self .subTest (f'{ module } : not strict' ):
1912- self .check_compatible_here (module , strict = False )
1917+ if not Py_GIL_DISABLED :
1918+ with self .subTest (f'{ module } : not strict' ):
1919+ self .check_compatible_here (module , strict = False )
19131920 with self .subTest (f'{ module } : strict, not fresh' ):
19141921 self .check_compatible_here (module , strict = True )
19151922 with self .subTest (f'{ module } : strict, fresh' ):
@@ -1930,8 +1937,9 @@ def test_multi_init_extension_non_isolated_compat(self):
19301937 self .check_incompatible_here (modname , filename , isolated = True )
19311938 with self .subTest (f'{ modname } : not isolated' ):
19321939 self .check_incompatible_here (modname , filename , isolated = False )
1933- with self .subTest (f'{ modname } : not strict' ):
1934- self .check_compatible_here (modname , filename , strict = False )
1940+ if not Py_GIL_DISABLED :
1941+ with self .subTest (f'{ modname } : not strict' ):
1942+ self .check_compatible_here (modname , filename , strict = False )
19351943
19361944 @unittest .skipIf (_testmultiphase is None , "test requires _testmultiphase module" )
19371945 def test_multi_init_extension_per_interpreter_gil_compat (self ):
@@ -1949,16 +1957,18 @@ def test_multi_init_extension_per_interpreter_gil_compat(self):
19491957 with self .subTest (f'{ modname } : not isolated, strict' ):
19501958 self .check_compatible_here (modname , filename ,
19511959 strict = True , isolated = False )
1952- with self .subTest (f'{ modname } : not isolated, not strict' ):
1953- self .check_compatible_here (modname , filename ,
1954- strict = False , isolated = False )
1960+ if not Py_GIL_DISABLED :
1961+ with self .subTest (f'{ modname } : not isolated, not strict' ):
1962+ self .check_compatible_here (modname , filename ,
1963+ strict = False , isolated = False )
19551964
19561965 @unittest .skipIf (_testinternalcapi is None , "requires _testinternalcapi" )
19571966 def test_python_compat (self ):
19581967 module = 'threading'
19591968 require_pure_python (module )
1960- with self .subTest (f'{ module } : not strict' ):
1961- self .check_compatible_here (module , strict = False )
1969+ if not Py_GIL_DISABLED :
1970+ with self .subTest (f'{ module } : not strict' ):
1971+ self .check_compatible_here (module , strict = False )
19621972 with self .subTest (f'{ module } : strict, not fresh' ):
19631973 self .check_compatible_here (module , strict = True )
19641974 with self .subTest (f'{ module } : strict, fresh' ):
0 commit comments