From 7f1bf44aa83c4d7d67d5f14fadd2e147e913ed99 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 2 Apr 2019 17:25:14 +0200 Subject: [PATCH] _compare_eq_dict: display number of different items --- src/_pytest/assertion/util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 231dd040d..08507a924 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -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)] @@ -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() )