bpo-30764: test_subprocess uses SuppressCrashReport (#2405) · python/cpython@cdee3f1
@@ -2563,37 +2563,40 @@ def test_communicate_BrokenPipeError_stdin_close_with_timeout(self):
25632563proc.communicate(timeout=999)
25642564mock_proc_stdin.close.assert_called_once_with()
256525652566-@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')
25682568def test_child_terminated_in_stopped_state(self):
25692569"""Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
25702570PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME).
25712571libc_name = ctypes.util.find_library('c')
25722572libc = ctypes.CDLL(libc_name)
25732573if 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"""
25772577 import ctypes
2578+ import faulthandler
2579+ from test.support import SuppressCrashReport
2580+25782581 libc = ctypes.CDLL({libc_name!r})
25792582 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])
25922595try:
25932596returncode = child.wait()
2594-except Exception as e:
2597+except:
25952598child.kill() # Clean up the hung stopped process.
2596-raise e
2599+raise
25972600self.assertNotEqual(0, returncode)
25982601self.assertLess(returncode, 0) # signal death, likely SIGSEGV.
25992602