Skip to content

Commit 3418657

Browse files
committed
fix #25 use context mode for long diffs
1 parent eda3dd0 commit 3418657

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

pytest_icdiff.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def pytest_assertrepr_compare(config, op, left, right):
5252
else:
5353
color_off = icdiff.color_codes['none']
5454

55-
icdiff_lines = list(differ.make_table(pretty_left, pretty_right, context=True))
55+
icdiff_lines = list(differ.make_table(pretty_left, pretty_right))
56+
if len(icdiff_lines) > 50:
57+
icdiff_lines = list(differ.make_table(pretty_left, pretty_right, context=True))
5658

5759
return ['equals failed'] + [color_off + l for l in icdiff_lines]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read(fname):
1313

1414
setup(
1515
name='pytest-icdiff',
16-
version='0.5',
16+
version='0.6',
1717
author='Harry Percival',
1818
author_email='[email protected]',
1919
maintainer='Harry Percival',

tests/test_pytest_icdiff.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,17 @@ def test_one():
275275
)
276276
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
277277
assert f"123456 123456{GREEN_ON}7" in output
278+
279+
280+
def test_really_long_diffs_use_context_mode(testdir):
281+
testdir.makepyfile(
282+
f"""
283+
def test_one():
284+
one = list(range(100))
285+
two = list(range(20)) + ["X"] + list(range(20, 50)) + ["Y"] + list(range(53, 100))
286+
assert one == two
287+
"""
288+
)
289+
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
290+
assert len(output.splitlines()) < 50
291+
assert "---" in output # context split marker

0 commit comments

Comments
 (0)