diff options
Diffstat (limited to 'Lib/test/script_helper.py')
-rw-r--r-- | Lib/test/script_helper.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py index b29392ff0a..07d167d936 100644 --- a/Lib/test/script_helper.py +++ b/Lib/test/script_helper.py @@ -20,7 +20,7 @@ from test.support import make_legacy_pyc, strip_python_stderr, temp_dir # Cached result of the expensive test performed in the function below. __cached_interp_requires_environment = None -def _interpreter_requires_environment(): +def interpreter_requires_environment(): """ Returns True if our sys.executable interpreter requires environment variables in order to be able to run at all. @@ -57,7 +57,7 @@ _PythonRunResult = collections.namedtuple("_PythonRunResult", # Executing the interpreter in a subprocess def run_python_until_end(*args, **env_vars): - env_required = _interpreter_requires_environment() + env_required = interpreter_requires_environment() if '__isolated' in env_vars: isolated = env_vars.pop('__isolated') else: @@ -95,10 +95,30 @@ def run_python_until_end(*args, **env_vars): def _assert_python(expected_success, *args, **env_vars): res, cmd_line = run_python_until_end(*args, **env_vars) if (res.rc and expected_success) or (not res.rc and not expected_success): - raise AssertionError( - "Process return code is %d, command line was: %r, " - "stderr follows:\n%s" % (res.rc, cmd_line, - res.err.decode('ascii', 'ignore'))) + # Limit to 80 lines to ASCII characters + maxlen = 80 * 100 + out, err = res.out, res.err + if len(out) > maxlen: + out = b'(... truncated stdout ...)' + out[-maxlen:] + if len(err) > maxlen: + err = b'(... truncated stderr ...)' + err[-maxlen:] + out = out.decode('ascii', 'replace').rstrip() + err = err.decode('ascii', 'replace').rstrip() + raise AssertionError("Process return code is %d\n" + "command line: %r\n" + "\n" + "stdout:\n" + "---\n" + "%s\n" + "---\n" + "\n" + "stderr:\n" + "---\n" + "%s\n" + "---" + % (res.rc, cmd_line, + out, + err)) return res def assert_python_ok(*args, **env_vars): |