@@ -7155,9 +7155,9 @@ def test_datetime_from_timestamp(self):
71557155
71567156                    self .assertEqual (dt_orig , dt_rt )
71577157
7158-     def  assert_python_ok_in_subinterp (self , script ,
7159-                                        setup = '_testcapi.test_datetime_capi()' ,
7160-                                        config = 'isolated' ):
7158+     def  assert_python_in_subinterp (self ,  check_if_ok :  bool , script ,
7159+                                    setup = '_testcapi.test_datetime_capi()' ,
7160+                                    config = 'isolated' ):
71617161        # iOS requires the use of the custom framework loader, 
71627162        # not the ExtensionFileLoader. 
71637163        if  sys .platform  ==  "ios" :
@@ -7201,7 +7201,10 @@ def assert_python_ok_in_subinterp(self, script,
72017201        code  =  code .replace ('$SETUP$' , setup )
72027202        code  =  code .replace ('$SCRIPT$' , textwrap .indent (script , '\x20 ' * 4 ))
72037203
7204-         res  =  script_helper .assert_python_ok ('-c' , code )
7204+         if  check_if_ok :
7205+             res  =  script_helper .assert_python_ok ('-c' , code )
7206+         else :
7207+             res  =  script_helper .assert_python_failure ('-c' , code )
72057208        return  res 
72067209
72077210    def  test_type_check_in_subinterp (self ):
@@ -7217,11 +7220,11 @@ def run(type_checker, obj):
72177220            run(_testcapi.datetime_check_time,     _datetime.time(12, 30)) 
72187221            run(_testcapi.datetime_check_delta,    _datetime.timedelta(1)) 
72197222            run(_testcapi.datetime_check_tzinfo,   _datetime.tzinfo()) 
7220-         """ )
7221-         self .assert_python_ok_in_subinterp ( script , '' )
7223+              """ )
7224+         self .assert_python_in_subinterp ( True ,  script , '' )
72227225        if  _interpreters  is  not   None :
72237226            with  self .subTest (name  :=  'legacy' ):
7224-                 self .assert_python_ok_in_subinterp ( script , '' , name )
7227+                 self .assert_python_in_subinterp ( True ,  script , '' , name )
72257228
72267229
72277230class  ExtensionModuleTests (unittest .TestCase ):
@@ -7316,7 +7319,7 @@ def gen():
73167319
73177320            it = gen() 
73187321            next(it) 
7319-         """ )
7322+              """ )
73207323        res  =  script_helper .assert_python_ok ('-c' , script )
73217324        self .assertFalse (res .err )
73227325
@@ -7336,7 +7339,7 @@ def gen():
73367339
73377340            it = gen() 
73387341            next(it) 
7339-         """ )
7342+              """ )
73407343        res  =  script_helper .assert_python_ok ('-c' , script )
73417344        self .assertFalse (res .err )
73427345
@@ -7352,20 +7355,18 @@ def gen():
73527355
73537356            it = gen() 
73547357            next(it) 
7355-         """ )
7356- 
7358+             """ )
73577359        with  self .subTest ('PyDateTime_IMPORT by MainInterpreter' ):
7358-             res  =  CapiTest .assert_python_ok_in_subinterp (self , script )
7360+             res  =  CapiTest .assert_python_in_subinterp (self ,  True , script )
73597361            self .assertIn (b'ImportError: sys.meta_path is None' , res .err )
73607362
73617363        script2  =  f'_testcapi.test_datetime_capi()\n { script }  ' 
7362- 
73637364        with  self .subTest ('PyDateTime_IMPORT by Subinterpreter' ):
7364-             res  =  CapiTest .assert_python_ok_in_subinterp (self , script2 , '' )
7365+             res  =  CapiTest .assert_python_in_subinterp (self ,  True , script2 , '' )
73657366            self .assertFalse (res .err )
73667367
73677368        with  self .subTest ('PyDateTime_IMPORT by Main/Sub' ):
7368-             res  =  CapiTest .assert_python_ok_in_subinterp (self , script2 )
7369+             res  =  CapiTest .assert_python_in_subinterp (self , True ,  script2 ,  '' )
73697370            self .assertFalse (res .err )
73707371
73717372    def  test_static_type_before_shutdown (self ):
@@ -7375,8 +7376,8 @@ def test_static_type_before_shutdown(self):
73757376            timedelta = _testcapi.get_capi_types()['timedelta'] 
73767377            timedelta(days=1) 
73777378            assert '_datetime' in sys.modules 
7378-         """ )
7379-         CapiTest .assert_python_ok_in_subinterp (self , script )
7379+              """ )
7380+         CapiTest .assert_python_in_subinterp (self ,  True , script )
73807381
73817382    def  test_module_free (self ):
73827383        script  =  textwrap .dedent (""" 
@@ -7392,15 +7393,15 @@ def test_module_free(self):
73927393                del _datetime 
73937394                gc.collect() 
73947395                assert len(ws) == 0 
7395-         """ )
7396+              """ )
73967397        script_helper .assert_python_ok ('-c' , script )
73977398
73987399    @unittest .skipIf (not  support .Py_DEBUG , "Debug builds only" ) 
73997400    def  test_no_leak (self ):
74007401        script  =  textwrap .dedent (""" 
74017402            import datetime 
74027403            datetime.datetime.strptime('20000101', '%Y%m%d').strftime('%Y%m%d') 
7403-         """ )
7404+              """ )
74047405        res  =  script_helper .assert_python_ok ('-X' , 'showrefcount' , '-c' , script )
74057406        self .assertIn (b'[0 refs, 0 blocks]' , res .err )
74067407
0 commit comments