[py-svn] commit/pytest: RonnyPfannschmidt: test and implement showing verbose assert repr for py.test -vv

Bitbucket commits-noreply at bitbucket.org
Wed Jun 27 17:27:40 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/2e06f917619d/
changeset:   2e06f917619d
user:        RonnyPfannschmidt
date:        2012-06-27 17:26:55
summary:     test and implement showing verbose assert repr for py.test -vv
affected #:  4 files

diff -r 6d5db6fbe405aacc5b828ec1f461f7699fa25664 -r 2e06f917619d045818b48651714c1ea5d59056e4 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -46,6 +46,8 @@
 
   - 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 -r 6d5db6fbe405aacc5b828ec1f461f7699fa25664 -r 2e06f917619d045818b48651714c1ea5d59056e4 _pytest/assertion/__init__.py
--- a/_pytest/assertion/__init__.py
+++ b/_pytest/assertion/__init__.py
@@ -73,8 +73,12 @@
     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 -r 6d5db6fbe405aacc5b828ec1f461f7699fa25664 -r 2e06f917619d045818b48651714c1ea5d59056e4 _pytest/assertion/util.py
--- a/_pytest/assertion/util.py
+++ b/_pytest/assertion/util.py
@@ -121,9 +121,6 @@
     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 -r 6d5db6fbe405aacc5b828ec1f461f7699fa25664 -r 2e06f917619d045818b48651714c1ea5d59056e4 testing/test_assertion.py
--- a/testing/test_assertion.py
+++ b/testing/test_assertion.py
@@ -150,6 +150,29 @@
         "*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'])

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list