diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -48,7 +48,7 @@ support.unlink(filename) class FaultHandlerTests(unittest.TestCase): - def get_output(self, code, filename=None): + def get_output(self, code, filename=None, extra_args=()): """ Run the specified code in Python (in a new child process) and read the output from the standard error or from a file (if filename is set). @@ -61,7 +61,8 @@ options = {} if prepare_subprocess: options['preexec_fn'] = prepare_subprocess - process = script_helper.spawn_python('-c', code, **options) + args = list(extra_args) + ['-c', code] + process = script_helper.spawn_python(*args, **options) stdout, stderr = process.communicate() exitcode = process.wait() output = support.strip_python_stderr(stdout) @@ -77,7 +78,8 @@ return output.splitlines(), exitcode def check_fatal_error(self, code, line_number, name_regex, - filename=None, all_threads=True, other_regex=None): + filename=None, all_threads=True, other_regex=None, + extra_args=()): """ Check that the fault handler for fatal errors is enabled and check the traceback from the child process output. @@ -100,11 +102,30 @@ header=re.escape(header)) if other_regex: regex += '|' + other_regex - output, exitcode = self.get_output(code, filename) + output, exitcode = self.get_output(code, filename, extra_args) output = '\n'.join(output) self.assertRegex(output, regex) self.assertNotEqual(exitcode, 0) + def test_X_option(self): + self.check_fatal_error(""" +import faulthandler +faulthandler._sigsegv() +""".strip(), + 2, + 'Segmentation fault', + extra_args=['-X', 'faulthandler']) + + def test_env_var(self): + with support.EnvironmentVarGuard() as env: + env['PYTHONFAULTHANDLER'] = 'YesPlease' + self.check_fatal_error(""" +import sys, os, faulthandler +faulthandler._sigsegv() +""".strip(), + 2, + 'Segmentation fault') + def test_read_null(self): self.check_fatal_error(""" import faulthandler