Commits

Floris Bruynooghe committed 71dfb23

Don't hide values of builtins (issue8)

When a statement gets reinterpreted the current implementation goes
out of it's way to to not show the result of the call but rather the
call itself. This means things like "len(l) == 42" will be shown as
"len([0, ...]) == 42" instead of the more desirable "666 == 42". So
this patch reverts that behaviour to show the actual results of
builtins again.

Comments (0)

Files changed (3)

 
 - fix (pytest-) issue20 path.samefile(relpath) works as expected now
 
+- fix (pytest-) issue8 len(long_list) now shows the lenght of the list
+
 Changes between 1.3.4 and 1.4.0
 ==================================================
 

py/_code/_assertionnew.py

             result = self.frame.eval(co, **ns)
         except Exception:
             raise Failure(explanation)
-        # Only show result explanation if it's not a builtin call or returns a
-        # bool.
-        if not isinstance(call.func, ast.Name) or \
-                not self._is_builtin_name(call.func):
-            source = "isinstance(__exprinfo_value, bool)"
-            co = self._compile(source)
-            try:
-                is_bool = self.frame.eval(co, __exprinfo_value=result)
-            except Exception:
-                is_bool = False
-            if not is_bool:
-                pattern = "%s\n{%s = %s\n}"
-                rep = self.frame.repr(result)
-                explanation = pattern % (rep, rep, explanation)
+        pattern = "%s\n{%s = %s\n}"
+        rep = self.frame.repr(result)
+        explanation = pattern % (rep, rep, explanation)
         return explanation, result
 
     def _is_builtin_name(self, name):

testing/code/test_assertion.py

         s = str(e)
         assert s.startswith("assert 1 == 2")
 
+def test_len():
+    l = list(xrange(42))
+    try:
+        assert len(l) == 100
+    except AssertionError:
+        e = exvalue()
+        s = str(e)
+        assert s.startswith("assert 42 == 100")
+        assert "where 42 = len([" in s
+
 def test_assert_non_string_message():
     class A:
         def __str__(self):