1 new commit in pytest:
https://bitbucket.org/hpk42/pytest/commits/121888e5a1f6/
Changeset: 121888e5a1f6
User: hpk42
Date: 2013-12-12 06:41:48
Summary: fix expicit assert messages for Python2.6: it turns out python2.6
instantiates the AssertionError differently for tuples. Test
and fix to neutralize it.
Affected #: 2 files
diff -r 4b3ab8c3b715d5bb76ee347885607977cf400ccc -r
121888e5a1f6844e33b89731e14b50f54dc30777 _pytest/assertion/reinterpret.py
--- a/_pytest/assertion/reinterpret.py
+++ b/_pytest/assertion/reinterpret.py
@@ -1,18 +1,26 @@
import sys
import py
from _pytest.assertion.util import BuiltinAssertionError
+u = py.builtin._totext
class AssertionError(BuiltinAssertionError):
def __init__(self, *args):
BuiltinAssertionError.__init__(self, *args)
if args:
+ # on Python2.6 we get len(args)==2 for: assert 0, (x,y)
+ # on Python2.7 and above we always get len(args) == 1
+ # with args[0] being the (x,y) tuple.
+ if len(args) > 1:
+ toprint = args
+ else:
+ toprint = args[0]
try:
- self.msg = py.builtin._totext(args[0])
+ self.msg = u(toprint)
except Exception:
- self.msg = py.builtin._totext(
+ self.msg = u(
"<[broken __repr__] %s at %0xd>"
- % (args[0].__class__, id(args[0])))
+ % (toprint.__class__, id(toprint)))
else:
f = py.code.Frame(sys._getframe(1))
try:
diff -r 4b3ab8c3b715d5bb76ee347885607977cf400ccc -r
121888e5a1f6844e33b89731e14b50f54dc30777 testing/test_assertion.py
--- a/testing/test_assertion.py
+++ b/testing/test_assertion.py
@@ -386,3 +386,16 @@
result.stdout.fnmatch_lines("""
<Module*>
""")
+
+def test_AssertionError_message(testdir):
+ testdir.makepyfile("""
+ def test_hello():
+ x,y = 1,2
+ assert 0, (x,y)
+ """)
+ result = testdir.runpytest()
+ result.stdout.fnmatch_lines("""
+ *def test_hello*
+ *assert 0, (x,y)*
+ *AssertionError: (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.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit