@@ -2563,37 +2563,40 @@ def test_communicate_BrokenPipeError_stdin_close_with_timeout(self):
2563
2563
proc .communicate (timeout = 999 )
2564
2564
mock_proc_stdin .close .assert_called_once_with ()
2565
2565
2566
- @unittest .skipIf (not ctypes , 'ctypes module required. ' )
2567
- @unittest .skipIf (not sys .executable , 'Test requires sys.executable. ' )
2566
+ @unittest .skipIf (not ctypes , 'ctypes module required' )
2567
+ @unittest .skipIf (not sys .executable , 'Test requires sys.executable' )
2568
2568
def test_child_terminated_in_stopped_state (self ):
2569
2569
"""Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
2570
2570
PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME).
2571
2571
libc_name = ctypes .util .find_library ('c' )
2572
2572
libc = ctypes .CDLL (libc_name )
2573
2573
if not hasattr (libc , 'ptrace' ):
2574
- raise unittest .SkipTest ('ptrace() required. ' )
2575
- test_ptrace = subprocess . Popen (
2576
- [ sys . executable , '-c' , """if True:
2574
+ raise unittest .SkipTest ('ptrace() required' )
2575
+
2576
+ code = textwrap . dedent ( f """
2577
2577
import ctypes
2578
+ import faulthandler
2579
+ from test.support import SuppressCrashReport
2580
+
2578
2581
libc = ctypes.CDLL({ libc_name !r} )
2579
2582
libc.ptrace({ PTRACE_TRACEME } , 0, 0)
2580
- """ . format ( libc_name = libc_name , PTRACE_TRACEME = PTRACE_TRACEME )
2581
- ])
2582
- if test_ptrace . wait () != 0 :
2583
- raise unittest . SkipTest ( 'ptrace() failed - unable to test.' )
2584
- child = subprocess . Popen (
2585
- [ sys . executable , '-c' , """if True:
2586
- import ctypes, faulthandler
2587
- libc = ctypes.CDLL({libc_name!r})
2588
- libc.ptrace({PTRACE_TRACEME}, 0, 0)
2589
- faulthandler._sigsegv() # Crash the process.
2590
- """ . format ( libc_name = libc_name , PTRACE_TRACEME = PTRACE_TRACEME )
2591
- ])
2583
+ """ )
2584
+
2585
+ child = subprocess . Popen ([ sys . executable , '-c' , code ])
2586
+ if child . wait () != 0 :
2587
+ raise unittest . SkipTest ( 'ptrace() failed - unable to test' )
2588
+
2589
+ code += textwrap . dedent ( f"""
2590
+ with SuppressCrashReport():
2591
+ # Crash the process
2592
+ faulthandler._sigsegv()
2593
+ """ )
2594
+ child = subprocess . Popen ([ sys . executable , '-c' , code ])
2592
2595
try :
2593
2596
returncode = child .wait ()
2594
- except Exception as e :
2597
+ except :
2595
2598
child .kill () # Clean up the hung stopped process.
2596
- raise e
2599
+ raise
2597
2600
self .assertNotEqual (0 , returncode )
2598
2601
self .assertLess (returncode , 0 ) # signal death, likely SIGSEGV.
2599
2602
0 commit comments