Skip to content

Commit 745b476

Browse files
authored
Merge pull request #47 from MaksimMisin/prettier-multiline-string-diff
Better visualize differences in multiline strings
2 parents 3ed5767 + 80458c2 commit 745b476

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pytest_icdiff.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ def pytest_assertrepr_compare(config, op, left, right):
7676
half_cols = COLS / 2 - MARGINS
7777
TABSIZE = int(config.getoption("--icdiff-tabsize") or 2)
7878

79-
pretty_left = pformat(left, indent=TABSIZE, width=half_cols).splitlines()
80-
pretty_right = pformat(right, indent=TABSIZE, width=half_cols).splitlines()
79+
if isinstance(left, str) and isinstance(right, str):
80+
pretty_left = left.splitlines()
81+
pretty_right = right.splitlines()
82+
else:
83+
pretty_left = pformat(left, indent=TABSIZE, width=half_cols).splitlines()
84+
pretty_right = pformat(right, indent=TABSIZE, width=half_cols).splitlines()
8185
diff_cols = COLS - MARGINS
8286

8387
if len(pretty_left) < 3 or len(pretty_right) < 3:

tests/test_pytest_icdiff.py

+15
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ def test_one():
229229
assert comparison_line.count("hell") < 15
230230

231231

232+
def test_mutliline_strings_have_no_escaped_newlines(testdir):
233+
testdir.makepyfile(
234+
r"""
235+
def test_one():
236+
one = "a\nb\nc\nd"
237+
two = "a\nb\nc\ndd"
238+
assert one == two"""
239+
)
240+
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
241+
print(repr(output))
242+
assert "a" + " " * 36 in output
243+
assert "b" + " " * 36 in output
244+
assert "c" + " " * 36 in output
245+
246+
232247
def test_columns_are_calculated_outside_hook(testdir):
233248
"""
234249
ok for some reason if you get the TerminalWriter width

0 commit comments

Comments
 (0)