Skip to content

Commit

Permalink
Shorten extremely long output (#18)
Browse files Browse the repository at this point in the history
* Don't overwrite modified files

* Shorten extremely long output
  • Loading branch information
max-sixty authored Sep 6, 2021
1 parent 4ea599e commit cd71704
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pytest_accept/doctest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ def _to_doctest_format(output: str) -> str:
lines = output.splitlines()
blankline_sentinel = "<BLANKLINE>"
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):
Expand Down

0 comments on commit cd71704

Please sign in to comment.