Merge pull request #1951 from mattduck/feat/1512-dict-compare-output
Feat/1512 dict compare output
This commit is contained in:
commit
887c097f8e
1
AUTHORS
1
AUTHORS
|
@ -89,6 +89,7 @@ Martijn Faassen
|
||||||
Martin K. Scherer
|
Martin K. Scherer
|
||||||
Martin Prusse
|
Martin Prusse
|
||||||
Matt Bachmann
|
Matt Bachmann
|
||||||
|
Matt Duck
|
||||||
Matt Williams
|
Matt Williams
|
||||||
Matthias Hafner
|
Matthias Hafner
|
||||||
mbyt
|
mbyt
|
||||||
|
|
|
@ -4,15 +4,19 @@
|
||||||
* Testcase reports with a url attribute will now properly write this to junitxml.
|
* Testcase reports with a url attribute will now properly write this to junitxml.
|
||||||
Thanks `@fushi`_ for the PR
|
Thanks `@fushi`_ for the PR
|
||||||
|
|
||||||
*
|
* Remove common items from dict comparision output when verbosity=1. Also update
|
||||||
|
the truncation message to make it clearer that pytest truncates all
|
||||||
*
|
assertion messages if verbosity < 2 (`#1512`_).
|
||||||
|
Thanks `@mattduck`_ for the PR
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
.. _@fushi: https://github.com/fushi
|
.. _@fushi: https://github.com/fushi
|
||||||
|
.. _@mattduck: https://github.com/mattduck
|
||||||
|
|
||||||
|
.. _#1512: https://github.com/pytest-dev/pytest/issues/1512
|
||||||
|
|
||||||
|
|
||||||
3.0.2
|
3.0.2
|
||||||
|
|
|
@ -131,14 +131,21 @@ def pytest_runtest_setup(item):
|
||||||
config=item.config, op=op, left=left, right=right)
|
config=item.config, op=op, left=left, right=right)
|
||||||
for new_expl in hook_result:
|
for new_expl in hook_result:
|
||||||
if new_expl:
|
if new_expl:
|
||||||
|
|
||||||
|
# Truncate lines if required
|
||||||
if (sum(len(p) for p in new_expl[1:]) > 80*8 and
|
if (sum(len(p) for p in new_expl[1:]) > 80*8 and
|
||||||
item.config.option.verbose < 2 and
|
item.config.option.verbose < 2 and
|
||||||
not _running_on_ci()):
|
not _running_on_ci()):
|
||||||
show_max = 10
|
show_max = 10
|
||||||
truncated_lines = len(new_expl) - show_max
|
truncated_count = len(new_expl) - show_max
|
||||||
new_expl[show_max:] = [py.builtin._totext(
|
new_expl[show_max - 1] += " ..."
|
||||||
'Detailed information truncated (%d more lines)'
|
new_expl[show_max:] = [
|
||||||
', use "-vv" to show' % truncated_lines)]
|
py.builtin._totext(""),
|
||||||
|
py.builtin._totext('...Full output truncated (%d more lines)'
|
||||||
|
', use "-vv" to show' % truncated_count
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
new_expl = [line.replace("\n", "\\n") for line in new_expl]
|
new_expl = [line.replace("\n", "\\n") for line in new_expl]
|
||||||
res = py.builtin._totext("\n~").join(new_expl)
|
res = py.builtin._totext("\n~").join(new_expl)
|
||||||
if item.config.getvalue("assertmode") == "rewrite":
|
if item.config.getvalue("assertmode") == "rewrite":
|
||||||
|
|
|
@ -256,8 +256,8 @@ def _compare_eq_dict(left, right, verbose=False):
|
||||||
explanation = []
|
explanation = []
|
||||||
common = set(left).intersection(set(right))
|
common = set(left).intersection(set(right))
|
||||||
same = dict((k, left[k]) for k in common if left[k] == right[k])
|
same = dict((k, left[k]) for k in common if left[k] == right[k])
|
||||||
if same and not verbose:
|
if same and verbose < 2:
|
||||||
explanation += [u('Omitting %s identical items, use -v to show') %
|
explanation += [u('Omitting %s identical items, use -vv to show') %
|
||||||
len(same)]
|
len(same)]
|
||||||
elif same:
|
elif same:
|
||||||
explanation += [u('Common items:')]
|
explanation += [u('Common items:')]
|
||||||
|
|
|
@ -351,8 +351,16 @@ class TestAssert_reprcompare:
|
||||||
for line in lines[1:]:
|
for line in lines[1:]:
|
||||||
assert 'b' not in line
|
assert 'b' not in line
|
||||||
|
|
||||||
def test_dict_omitting_verbose(self):
|
def test_dict_omitting_with_verbosity_1(self):
|
||||||
lines = callequal({'a': 0, 'b': 1}, {'a': 1, 'b': 1}, verbose=True)
|
""" 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 lines[1].startswith('Common items:')
|
||||||
assert 'Omitting' not in lines[1]
|
assert 'Omitting' not in lines[1]
|
||||||
assert lines[2] == "{'b': 1}"
|
assert lines[2] == "{'b': 1}"
|
||||||
|
|
Loading…
Reference in New Issue