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 @@ -58,10 +58,13 @@ build, and replace "Current thread 0x00007f8d8fbd9700" by "Current thread XXX". """ + return self._get_output(['-c', code], filename) + + def _get_output(self, python_args, filename=None): options = {} if prepare_subprocess: options['preexec_fn'] = prepare_subprocess - process = script_helper.spawn_python('-c', code, **options) + process = script_helper.spawn_python(*python_args, **options) stdout, stderr = process.communicate() exitcode = process.wait() output = support.strip_python_stderr(stdout) @@ -76,6 +79,17 @@ output) return output.splitlines(), exitcode + def get_file_output(self, code, scriptname, filename=None): + """ + Run the specified code in Python (in a new child process) as + a file with the given script name. + + See the get_output() docstring for more information. + """ + with script_helper.temp_dir() as temp_dir: + scriptpath = script_helper.make_script(temp_dir, scriptname, code) + return self._get_output([scriptpath], filename) + def check_fatal_error(self, code, line_number, name_regex, filename=None, all_threads=True, other_regex=None): """ @@ -340,22 +354,23 @@ waiter.join() """.strip() code = code.format(filename=repr(filename)) - output, exitcode = self.get_output(code, filename) + output, exitcode = self.get_file_output(code, 'test', filename) output = '\n'.join(output) if filename: lineno = 8 else: lineno = 10 + # We allow a terminal '...' for long install paths. regex = """ ^Thread 0x[0-9a-f]+: -(?: File ".*threading.py", line [0-9]+ in [_a-z]+ -){{1,3}} File "", line 23 in run - File ".*threading.py", line [0-9]+ in _bootstrap_inner - File ".*threading.py", line [0-9]+ in _bootstrap +(?: File ".*(threading.py|\.\.\.)", line [0-9]+ in [_a-z]+ +){{1,3}} File ".*test.py", line 23 in run + File ".*(threading.py|\.\.\.)", line [0-9]+ in _bootstrap_inner + File ".*(threading.py|\.\.\.)", line [0-9]+ in _bootstrap Current thread XXX: - File "", line {lineno} in dump - File "", line 28 in $ + File ".*test.py", line {lineno} in dump + File ".*test.py", line 28 in $ """.strip() regex = regex.format(lineno=lineno) self.assertRegex(output, regex)