Skip to content

Commit

Permalink
Don't display dict common items if verbosity=1
Browse files Browse the repository at this point in the history
Part one of pytest-dev#1512.

If verbosity=1, assertion explanations are truncated at 10 lines. In this
situation, it's more important to tell the user which dictionary items are
different than which are the same.
  • Loading branch information
mattduck committed Sep 19, 2016
1 parent 8639bf7 commit ff31dbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions _pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ def _compare_eq_dict(left, right, verbose=False):
explanation = []
common = set(left).intersection(set(right))
same = dict((k, left[k]) for k in common if left[k] == right[k])
if same and not verbose:
explanation += [u('Omitting %s identical items, use -v to show') %
if same and verbose < 2:
explanation += [u('Omitting %s identical items, use -vv to show') %
len(same)]
elif same:
explanation += [u('Common items:')]
Expand Down
12 changes: 10 additions & 2 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,16 @@ def test_dict_omitting(self):
for line in lines[1:]:
assert 'b' not in line

def test_dict_omitting_verbose(self):
lines = callequal({'a': 0, 'b': 1}, {'a': 1, 'b': 1}, verbose=True)
def test_dict_omitting_with_verbosity_1(self):
""" Ensure differing items are visible for verbosity=1 (#1512) """
lines = callequal({'a': 0, 'b': 1}, {'a': 1, 'b': 1}, verbose=1)
assert lines[1].startswith('Omitting 1 identical item')
assert lines[2].startswith('Differing items')
assert lines[3] == "{'a': 0} != {'a': 1}"
assert 'Common items' not in lines

def test_dict_omitting_with_verbosity_2(self):
lines = callequal({'a': 0, 'b': 1}, {'a': 1, 'b': 1}, verbose=2)
assert lines[1].startswith('Common items:')
assert 'Omitting' not in lines[1]
assert lines[2] == "{'b': 1}"
Expand Down

0 comments on commit ff31dbe

Please sign in to comment.