Skip to content

Commit cd71704

Browse files
authored
Shorten extremely long output (#18)
* Don't overwrite modified files * Shorten extremely long output
1 parent 4ea599e commit cd71704

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pytest_accept/doctest_plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ def _to_doctest_format(output: str) -> str:
123123
lines = output.splitlines()
124124
blankline_sentinel = "<BLANKLINE>"
125125
transformed_lines = [line if line else blankline_sentinel for line in lines]
126-
return "\n".join(transformed_lines)
126+
# In some pathological cases, this can crash an editor.
127+
shortened_lines = [
128+
line if len(line) < 1000 else f"{line[:50]}...{line[-50:]}"
129+
for line in transformed_lines
130+
]
131+
# Again, only for the pathological cases.
132+
if len(shortened_lines) > 1000:
133+
shortened_lines = shortened_lines[:50] + ["..."] + shortened_lines[-50:]
134+
return "\n".join(shortened_lines)
127135

128136

129137
def pytest_sessionfinish(session, exitstatus):

0 commit comments

Comments
 (0)