Skip to content

Commit 7801d4a

Browse files
committed
shorter diffs too
1 parent 89b8fc5 commit 7801d4a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pytest_icdiff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def pytest_assertrepr_compare(config, op, left, right):
2121
if len(wide_left) < 3 or len(wide_right) < 3:
2222
shortest_left = pformat(left, indent=2, width=1).splitlines()
2323
shortest_right = pformat(right, indent=2, width=1).splitlines()
24-
cols = max(len(l) for l in shortest_left + shortest_right) * 2
24+
longest_line_length = max(len(l) for l in shortest_left + shortest_right)
2525
else:
2626
longest_line_length = max(len(l) for l in wide_left + wide_right)
27-
cols = int(min(longest_line_length, cols / 2))
27+
cols = int(min(longest_line_length, cols))
2828

2929
pretty_left = pformat(left, indent=2, width=cols / 2).splitlines()
3030
pretty_right = pformat(right, indent=2, width=cols / 2).splitlines()

tests/test_pytest_icdiff.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_a():
190190
assert drilldown_expression in output
191191

192192

193-
def test_long_lines_in_comparators_are_wrapped_sensibly(testdir):
193+
def test_long_lines_in_comparators_are_wrapped_sensibly_multiline(testdir):
194194
left = {1: "hello " * 20}
195195
right = {1: "hella " * 20}
196196
testdir.makepyfile(
@@ -201,4 +201,21 @@ def test_one():
201201
)
202202
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
203203
comparison_line = next(l for l in output.splitlines() if '1:' in l and "assert" not in l)
204-
assert len(comparison_line) < 120
204+
assert comparison_line.count('hell') < 13
205+
206+
def test_long_lines_in_comparators_are_wrapped_sensibly_singleline(testdir):
207+
left = "hello " * 10
208+
right = "hella " * 10
209+
testdir.makepyfile(
210+
f"""
211+
def test_one():
212+
assert {left!r} == {right!r}
213+
"""
214+
)
215+
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
216+
comparison_line = next(
217+
l for l in output.splitlines()
218+
if "hell" in l
219+
and "assert" not in l
220+
)
221+
assert comparison_line.count('hell') < 13

0 commit comments

Comments
 (0)