Skip to content

Commit 46f938b

Browse files
committed
feat: better differences for multiline strings
1 parent 3ed5767 commit 46f938b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pytest_icdiff.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def pytest_addoption(parser):
5656
action="store_true",
5757
help="pytest-icdiff: strip any trailing carriage return at the end of an input line",
5858
)
59+
parser.addoption(
60+
"--icdiff-multiline-string",
61+
default=False,
62+
action="store_true",
63+
help="pytest-icdiff: proper differences for multiline strings",
64+
)
5965

6066

6167
def pytest_assertrepr_compare(config, op, left, right):
@@ -76,8 +82,16 @@ def pytest_assertrepr_compare(config, op, left, right):
7682
half_cols = COLS / 2 - MARGINS
7783
TABSIZE = int(config.getoption("--icdiff-tabsize") or 2)
7884

79-
pretty_left = pformat(left, indent=TABSIZE, width=half_cols).splitlines()
80-
pretty_right = pformat(right, indent=TABSIZE, width=half_cols).splitlines()
85+
if (
86+
config.getoption("--icdiff-multiline-string")
87+
and isinstance(left, str)
88+
and isinstance(right, str)
89+
):
90+
pretty_left = left.splitlines()
91+
pretty_right = right.splitlines()
92+
else:
93+
pretty_left = pformat(left, indent=TABSIZE, width=half_cols).splitlines()
94+
pretty_right = pformat(right, indent=TABSIZE, width=half_cols).splitlines()
8195
diff_cols = COLS - MARGINS
8296

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

0 commit comments

Comments
 (0)