test and implement showing verbose assert repr for py.test -vv
This commit is contained in:
parent
ecec653e98
commit
74e55493d1
|
@ -46,6 +46,8 @@ Changes between 2.2.4 and 2.3.0.dev
|
||||||
|
|
||||||
- don't show deselected reason line if there is none
|
- don't show deselected reason line if there is none
|
||||||
|
|
||||||
|
- py.test -vv will show all of assert comparisations instead of truncating
|
||||||
|
|
||||||
Changes between 2.2.3 and 2.2.4
|
Changes between 2.2.3 and 2.2.4
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,12 @@ def pytest_runtest_setup(item):
|
||||||
def callbinrepr(op, left, right):
|
def callbinrepr(op, left, right):
|
||||||
hook_result = item.ihook.pytest_assertrepr_compare(
|
hook_result = item.ihook.pytest_assertrepr_compare(
|
||||||
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:
|
||||||
|
# Don't include pageloads of data unless we are very verbose (-vv)
|
||||||
|
if len(''.join(new_expl[1:])) > 80*8 and item.config.option.verbose < 2:
|
||||||
|
new_expl[1:] = ['Detailed information too verbose, truncated']
|
||||||
res = '\n~'.join(new_expl)
|
res = '\n~'.join(new_expl)
|
||||||
if item.config.getvalue("assertmode") == "rewrite":
|
if item.config.getvalue("assertmode") == "rewrite":
|
||||||
# The result will be fed back a python % formatting
|
# The result will be fed back a python % formatting
|
||||||
|
|
|
@ -121,9 +121,6 @@ def assertrepr_compare(op, left, right):
|
||||||
if not explanation:
|
if not explanation:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Don't include pageloads of data, should be configurable
|
|
||||||
if len(''.join(explanation)) > 80*8:
|
|
||||||
explanation = ['Detailed information too verbose, truncated']
|
|
||||||
|
|
||||||
return [summary] + explanation
|
return [summary] + explanation
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,29 @@ def test_sequence_comparison_uses_repr(testdir):
|
||||||
"*E*'y'*",
|
"*E*'y'*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def test_assert_compare_truncate_longmessage(testdir):
|
||||||
|
testdir.makepyfile(r"""
|
||||||
|
def test_long():
|
||||||
|
a = list(range(200))
|
||||||
|
b = a[::2]
|
||||||
|
a = '\n'.join(map(str, a))
|
||||||
|
b = '\n'.join(map(str, b))
|
||||||
|
assert a == b
|
||||||
|
""")
|
||||||
|
|
||||||
|
result = testdir.runpytest()
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*too verbose, truncated*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
result = testdir.runpytest('-vv')
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*- 197",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
@needsnewassert
|
@needsnewassert
|
||||||
def test_assertrepr_loaded_per_dir(testdir):
|
def test_assertrepr_loaded_per_dir(testdir):
|
||||||
testdir.makepyfile(test_base=['def test_base(): assert 1 == 2'])
|
testdir.makepyfile(test_base=['def test_base(): assert 1 == 2'])
|
||||||
|
|
Loading…
Reference in New Issue