@@ -589,32 +589,35 @@ def test_for_crash_traceback_with_redirected_stdout(self):
589
589
with TemporaryDirectory () as tmp_dir :
590
590
stdout_path = os .path .join (tmp_dir , "WinCMDLineTests.txt" )
591
591
592
- with open (stdout_path , "w" , encoding = "utf-8" ) as stdout_file , \
593
- subprocess .Popen (
592
+ with open (stdout_path , "w" ) as stdout_file , \
593
+ subprocess .Popen (
594
594
[sys .executable , '-i' , '-c' , script_command ],
595
595
stdin = None ,
596
596
stdout = stdout_file ,
597
597
stderr = subprocess .PIPE ,
598
- text = True , encoding = 'utf-8' , errors = 'replace'
599
- ) as process :
600
-
601
- time .sleep (3 )
602
-
603
- if process .poll () is None :
598
+ text = True , errors = 'replace'
599
+ ) as process :
600
+
601
+ stderr_output = ""
602
+
603
+ try :
604
+ process .wait (timeout = 3 )
605
+ self .fail (
606
+ "Process exited unexpectedly within the timeout."
607
+ )
608
+ except subprocess .TimeoutExpired :
604
609
process .kill ()
610
+ _ , stderr_output = process .communicate ()
605
611
606
- stderr_output = process .stderr .read ()
607
-
608
- has_crash_traceback = (
609
- "OSError" in stderr_output
610
- and len (stderr_output ) > 1200
611
- )
612
+ has_crash_traceback = (
613
+ "OSError" in stderr_output and
614
+ len (stderr_output ) > 1200
615
+ )
616
+
617
+ if has_crash_traceback :
618
+ self .fail ("Detected endless OSError traceback."
619
+ f"\n --- stderr ---\n { stderr_output [:1200 ]} " )
612
620
613
- if has_crash_traceback :
614
- self .fail (
615
- "Detected the endless OSError traceback.\n "
616
- f"Stderr was:\n { stderr_output [:1200 ]} "
617
- )
618
621
619
622
if __name__ == "__main__" :
620
623
unittest .main ()
0 commit comments