@@ -1459,6 +1459,22 @@ def check_compatible_shared(self, name, *, strict=False):
14591459 out = os .read (r , 100 )
14601460 self .assertEqual (out , b'okay' )
14611461
1462+ def check_incompatible_shared (self , name ):
1463+ # Differences from check_compatible_shared():
1464+ # * verify that import fails
1465+ # * "strict" is always True
1466+ __import__ (name )
1467+
1468+ r , w = self .pipe ()
1469+ ret = run_in_subinterp_with_config (
1470+ self .import_script (name , w ),
1471+ ** self .RUN_KWARGS ,
1472+ check_multi_interp_extensions = True ,
1473+ )
1474+ self .assertEqual (ret , 0 )
1475+ out = os .read (r , 100 ).decode ('utf-8' )
1476+ self .assertEqual (out , f'ImportError: module { name } does not support loading in subinterpreters' )
1477+
14621478 def check_compatible_isolated (self , name , * , strict = False ):
14631479 # Differences from check_compatible_shared():
14641480 # * subinterpreter in a new process
@@ -1480,6 +1496,26 @@ def check_compatible_isolated(self, name, *, strict=False):
14801496 self .assertEqual (err , b'' )
14811497 self .assertEqual (out , b'okay' )
14821498
1499+ def check_incompatible_isolated (self , name ):
1500+ # Differences from check_compatible_isolated():
1501+ # * verify that import fails
1502+ # * "strict" is always True
1503+ _ , out , err = script_helper .assert_python_ok ('-c' , textwrap .dedent (f'''
1504+ import _testcapi, sys
1505+ assert { name !r} not in sys.modules, { name !r}
1506+ ret = _testcapi.run_in_subinterp_with_config(
1507+ { self .import_script (name , "sys.stdout.fileno()" )!r} ,
1508+ **{ self .RUN_KWARGS } ,
1509+ check_multi_interp_extensions=True,
1510+ )
1511+ assert ret == 0, ret
1512+ ''' ))
1513+ self .assertEqual (err , b'' )
1514+ self .assertEqual (
1515+ out .decode ('utf-8' ),
1516+ f'ImportError: module { name } does not support loading in subinterpreters' ,
1517+ )
1518+
14831519 def test_builtin_compat (self ):
14841520 module = 'sys'
14851521 with self .subTest (f'{ module } : not strict' ):
@@ -1503,9 +1539,9 @@ def test_single_init_extension_compat(self):
15031539 with self .subTest (f'{ module } : not strict' ):
15041540 self .check_compatible_shared (module , strict = False )
15051541 with self .subTest (f'{ module } : strict, shared' ):
1506- self .check_compatible_shared (module )
1542+ self .check_incompatible_shared (module )
15071543 with self .subTest (f'{ module } : strict, isolated' ):
1508- self .check_compatible_isolated (module )
1544+ self .check_incompatible_isolated (module )
15091545
15101546 @unittest .skipIf (_testmultiphase is None , "test requires _testmultiphase module" )
15111547 def test_multi_init_extension_compat (self ):
0 commit comments