Skip to content

Commit 5fec793

Browse files
committed
_compare_eq_sequence: display number of extra items
1 parent e04936f commit 5fec793

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/_pytest/assertion/util.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,22 @@ def _compare_eq_iterable(left, right, verbose=0):
285285

286286
def _compare_eq_sequence(left, right, verbose=0):
287287
explanation = []
288-
for i in range(min(len(left), len(right))):
288+
len_left = len(left)
289+
len_right = len(right)
290+
for i in range(min(len_left, len_right)):
289291
if left[i] != right[i]:
290292
explanation += [u"At index %s diff: %r != %r" % (i, left[i], right[i])]
291293
break
292-
if len(left) > len(right):
294+
len_diff = len_left - len_right
295+
if len_diff > 0:
293296
explanation += [
294-
u"Left contains more items, first extra item: %s"
295-
% saferepr(left[len(right)])
297+
u"Left contains %d more items, first extra item: %s"
298+
% (len_diff, saferepr(left[len_right]))
296299
]
297-
elif len(left) < len(right):
300+
elif len_diff < 0:
298301
explanation += [
299-
u"Right contains more items, first extra item: %s"
300-
% saferepr(right[len(left)])
302+
u"Right contains %d more items, first extra item: %s"
303+
% (0 - len_diff, saferepr(right[len_left]))
301304
]
302305
return explanation
303306

0 commit comments

Comments
 (0)