From cd717046d9bfee2bc3936d88f3fe7b9a0bd4a451 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Mon, 6 Sep 2021 15:37:24 -0700 Subject: [PATCH] Shorten extremely long output (#18) * Don't overwrite modified files * Shorten extremely long output --- pytest_accept/doctest_plugin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pytest_accept/doctest_plugin.py b/pytest_accept/doctest_plugin.py index b52e10c..b8cbf44 100644 --- a/pytest_accept/doctest_plugin.py +++ b/pytest_accept/doctest_plugin.py @@ -123,7 +123,15 @@ def _to_doctest_format(output: str) -> str: lines = output.splitlines() blankline_sentinel = "" transformed_lines = [line if line else blankline_sentinel for line in lines] - return "\n".join(transformed_lines) + # In some pathological cases, this can crash an editor. + shortened_lines = [ + line if len(line) < 1000 else f"{line[:50]}...{line[-50:]}" + for line in transformed_lines + ] + # Again, only for the pathological cases. + if len(shortened_lines) > 1000: + shortened_lines = shortened_lines[:50] + ["..."] + shortened_lines[-50:] + return "\n".join(shortened_lines) def pytest_sessionfinish(session, exitstatus):