Skip to content

Commit 8de826c

Browse files
committed
assert: _diff_text: use repr() with line endings
1 parent bc95201 commit 8de826c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/_pytest/assertion/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]:
246246
wcwidth(ch) <= 0
247247
for ch in [ch for lines in left_lines + right_lines for ch in lines]
248248
):
249-
left_lines = [repr(x) for x in left_lines]
250-
right_lines = [repr(x) for x in right_lines]
249+
left_lines = [repr(x) for x in left.splitlines(True)]
250+
right_lines = [repr(x) for x in right.splitlines(True)]
251251
explanation += [
252252
"NOTE: Strings contain non-printable characters. Escaping them using repr()."
253253
]

testing/test_assertion.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,11 +1519,13 @@ def test_diff_different_line_endings():
15191519
r" line2",
15201520
]
15211521

1522-
# Only '\r' is considered non-printable
1522+
# Only '\r' is considered non-printable, repr() is used on original lines.
15231523
assert callequal("line1\r\nline2", "line1\nline2\r", verbose=2) == [
15241524
r"'line1\r\nline2' == 'line1\nline2\r'",
15251525
r"NOTE: Strings contain non-printable characters. Escaping them using repr().",
1526-
r" 'line1'",
1526+
r"- 'line1\n'",
1527+
r"+ 'line1\r\n'",
1528+
r"? ++",
15271529
r"- 'line2\r'",
15281530
r"? --",
15291531
r"+ 'line2'",

0 commit comments

Comments
 (0)