Fix pytest_assertrepr_compare on python3 (issue24)
The maxsize argument must be an integer and the devision syntax changed between python2 and python3.
This commit is contained in:
parent
70ceb946e4
commit
2f2586af72
|
@ -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
|
||||
----------------------------------------------
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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', '? +++']
|
||||
|
|
Loading…
Reference in New Issue