1313 cpython_only ,
1414 has_subprocess_support ,
1515 os_helper ,
16+ subTests ,
1617 SuppressCrashReport ,
1718 SHORT_TIMEOUT ,
1819)
@@ -461,8 +462,14 @@ def test_quiet_mode(self):
461462 self .assertEqual (p .returncode , 0 )
462463 self .assertEqual (output [:3 ], ">>>" )
463464
464- def test_pythonstartup_failure (self ):
465- startup_code = "1/0\n "
465+ @subTests (
466+ ("startup_code" , "expected_error" ),
467+ [
468+ ("some invalid syntax\n " , "SyntaxError: invalid syntax" ),
469+ ("1/0\n " , "ZeroDivisionError: division by zero" ),
470+ ],
471+ )
472+ def test_pythonstartup_failure (self , startup_code , expected_error ):
466473 startup_env = self .enterContext (
467474 new_pythonstartup_env (code = startup_code , histfile = ".asyncio_history" ))
468475
@@ -471,16 +478,14 @@ def test_pythonstartup_failure(self):
471478 env = os .environ | startup_env ,
472479 isolated = False ,
473480 custom = True )
474- p .stdin .write ("print('executed user code anyway') " )
481+ p .stdin .write ("print('user code', 'executed') \n " )
475482 output = kill_python (p )
476- expected = dedent (f"""\
477- File "{ startup_env ['PYTHONSTARTUP' ]} ", line 1, in <module>
478- 1/0
479- ~^~
480- ZeroDivisionError: division by zero
481- """ )
482- self .assertIn (expected , output )
483- self .assertIn ("executed user code anyway" , output )
483+
484+ tb_hint = f'File "{ startup_env ["PYTHONSTARTUP" ]} ", line 1'
485+ self .assertIn (tb_hint , output )
486+ self .assertIn (expected_error , output )
487+
488+ self .assertIn ("user code executed" , output )
484489
485490
486491if __name__ == "__main__" :
0 commit comments