Skip to content

Show a few diff lines when truncating string diffs #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
2.8.0.dev (compared to 2.7.X)
-----------------------------

- Fix #562: @nose.tools.istest now fully respected.
- fix issue562: @nose.tools.istest now fully respected.

- Fix issue736: Fix a bug where fixture params would be discarded when combined
- fix issue934: when string comparison fails and a diff is too large to display
without passing -vv, still show a few lines of the diff.
Thanks Florian Bruhin for the report and Bruno Oliveira for the PR.

- fix issue736: Fix a bug where fixture params would be discarded when combined
with parametrization markers.
Thanks to Markus Unterwaditzer for the PR.

Expand Down
7 changes: 5 additions & 2 deletions _pytest/assertion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ def callbinrepr(op, left, right):
if new_expl:
if (sum(len(p) for p in new_expl[1:]) > 80*8
and item.config.option.verbose < 2):
new_expl[1:] = [py.builtin._totext(
'Detailed information truncated, use "-vv" to show')]
show_max = 10
truncated_lines = len(new_expl) - show_max
new_expl[show_max:] = [py.builtin._totext(
'Detailed information truncated (%d more lines)'
', use "-vv" to show' % truncated_lines)]
new_expl = [line.replace("\n", "\\n") for line in new_expl]
res = py.builtin._totext("\n~").join(new_expl)
if item.config.getvalue("assertmode") == "rewrite":
Expand Down
7 changes: 6 additions & 1 deletion testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,13 @@ def test_long():
""")

result = testdir.runpytest()
# without -vv, truncate the message showing a few diff lines only
result.stdout.fnmatch_lines([
"*truncated*use*-vv*",
"*- 1",
"*- 3",
"*- 5",
"*- 7",
"*truncated (191 more lines)*use*-vv*",
])


Expand Down