From 2f2586af72dc7ca4b44556b439da0a59034240e6 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Tue, 15 Feb 2011 23:24:18 +0000 Subject: [PATCH] Fix pytest_assertrepr_compare on python3 (issue24) The maxsize argument must be an integer and the devision syntax changed between python2 and python3. --- CHANGELOG | 6 ++++++ _pytest/assertion.py | 4 ++-- testing/test_assertion.py | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9ba4dae81..d7589ab19 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Changes between 2.0.1 and 2.0.2 +---------------------------------------------- + +- fix issue24 - pytest_assertrepr_compare produces an in-line + exception on python3 + Changes between 2.0.0 and 2.0.1 ---------------------------------------------- diff --git a/_pytest/assertion.py b/_pytest/assertion.py index b142790a6..e2578242a 100644 --- a/_pytest/assertion.py +++ b/_pytest/assertion.py @@ -12,7 +12,7 @@ def pytest_addoption(parser): help="disable python assert expression reinterpretation."), def pytest_configure(config): - # The _pytesthook attribute on the AssertionError is used by + # The _reprcompare attribute on the py.code module is used by # py._code._assertionnew to detect this plugin was loaded and in # turn call the hooks defined here as part of the # DebugInterpreter. @@ -51,7 +51,7 @@ except NameError: def pytest_assertrepr_compare(op, left, right): """return specialised explanations for some operators/operands""" width = 80 - 15 - len(op) - 2 # 15 chars indentation, 1 space around op - left_repr = py.io.saferepr(left, maxsize=width/2) + left_repr = py.io.saferepr(left, maxsize=int(width/2)) right_repr = py.io.saferepr(right, maxsize=width-len(left_repr)) summary = '%s %s %s' % (left_repr, op, right_repr) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index c7187372e..bee3903cf 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -114,6 +114,10 @@ class TestAssert_reprcompare: expl = callequal(A(), '') assert not expl + def test_repr_no_exc(self): + expl = ' '.join(callequal('foo', 'bar')) + assert 'raised in repr()' not in expl + def test_reprcompare_notin(): detail = plugin.pytest_assertrepr_compare('not in', 'foo', 'aaafoobbb')[1:] assert detail == ["'foo' is contained here:", ' aaafoobbb', '? +++']