Skip to content

Commit

Permalink
_compare_eq_dict: display number of different items
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Apr 2, 2019
1 parent 231f343 commit b7b44e1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ def _compare_eq_set(left, right, verbose=0):

def _compare_eq_dict(left, right, verbose=0):
explanation = []
common = set(left).intersection(set(right))
set_left = set(left)
set_right = set(right)
common = set_left.intersection(set_right)
same = {k: left[k] for k in common if left[k] == right[k]}
if same and verbose < 2:
explanation += [u"Omitting %s identical items, use -vv to show" % len(same)]
Expand All @@ -334,15 +336,15 @@ def _compare_eq_dict(left, right, verbose=0):
explanation += [u"Differing items:"]
for k in diff:
explanation += [saferepr({k: left[k]}) + " != " + saferepr({k: right[k]})]
extra_left = set(left) - set(right)
extra_left = set_left - set_right
if extra_left:
explanation.append(u"Left contains more items:")
explanation.append(u"Left contains %d more items:" % len(extra_left))
explanation.extend(
pprint.pformat({k: left[k] for k in extra_left}).splitlines()
)
extra_right = set(right) - set(left)
extra_right = set_right - set_left
if extra_right:
explanation.append(u"Right contains more items:")
explanation.append(u"Right contains %d more items:" % len(extra_right))
explanation.extend(
pprint.pformat({k: right[k] for k in extra_right}).splitlines()
)
Expand Down

0 comments on commit b7b44e1

Please sign in to comment.