Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Abhijeet Kasurde
Adam Johnson
Adam Stewart
Adam Uhlir
Aditya Tripuraneni
Ahn Ki-Wook
Akhilesh Ramakrishnan
Akiomi Kamakura
Expand Down
1 change: 1 addition & 0 deletions changelog/14637.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pytest now correctly skips identical trailing characters in assertion text diffs even when the compared strings differ at the beginning.
2 changes: 1 addition & 1 deletion src/_pytest/assertion/compare_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _diff_text(
left = left[i:]
right = right[i:]
if len(left) == len(right):
for i in range(len(left)):
for i in range(1, len(left) + 1):
if left[-i] != right[-i]:
break
if i > 42:
Expand Down
8 changes: 8 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,14 @@ def test_text_skipping_trailing(self) -> None:
for line in lines:
assert "z" * 50 not in line

def test_text_skipping_trailing_when_prefix_differs(self) -> None:
# The trailing-skip branch must still work when the first characters differ.
lines = callequal("x" + "z" * 50, "y" + "z" * 50)
assert lines is not None
assert any("identical trailing" in line for line in lines)
for line in lines:
assert "z" * 50 not in line

def test_text_skipping_verbose(self) -> None:
lines = callequal("a" * 50 + "spam", "a" * 50 + "eggs", verbose=1)
assert lines is not None
Expand Down
Loading