From 74e55493d14e16bc02756189891037dd1ba65df0 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 27 Jun 2012 17:26:55 +0200 Subject: [PATCH] test and implement showing verbose assert repr for py.test -vv --- CHANGELOG | 2 ++ _pytest/assertion/__init__.py | 4 ++++ _pytest/assertion/util.py | 3 --- testing/test_assertion.py | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2e8ace0cf..827652f36 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -46,6 +46,8 @@ Changes between 2.2.4 and 2.3.0.dev - 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 ----------------------------------- diff --git a/_pytest/assertion/__init__.py b/_pytest/assertion/__init__.py index a91ab4831..4ead44fca 100644 --- a/_pytest/assertion/__init__.py +++ b/_pytest/assertion/__init__.py @@ -73,8 +73,12 @@ def pytest_runtest_setup(item): def callbinrepr(op, left, right): hook_result = item.ihook.pytest_assertrepr_compare( config=item.config, op=op, left=left, right=right) + for new_expl in hook_result: 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) if item.config.getvalue("assertmode") == "rewrite": # The result will be fed back a python % formatting diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 0be2d7c5b..2e0b22735 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -121,9 +121,6 @@ def assertrepr_compare(op, left, right): if not explanation: 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 diff --git a/testing/test_assertion.py b/testing/test_assertion.py index e67e010f7..f039bf476 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -150,6 +150,29 @@ def test_sequence_comparison_uses_repr(testdir): "*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 def test_assertrepr_loaded_per_dir(testdir): testdir.makepyfile(test_base=['def test_base(): assert 1 == 2'])