Make pytest_assert_binrepr work on python3 too

--HG--
branch : trunk
This commit is contained in:
Floris Bruynooghe 2010-09-22 18:42:04 +01:00
parent 4b2cb3acbe
commit 56b955dfb5
2 changed files with 8 additions and 5 deletions

View File

@ -33,6 +33,13 @@ def warn_about_missing_assertion():
" (are you using python -O?)")
# Provide basestring in python3
try:
basestring = basestring
except NameError:
basestring = str
def pytest_assert_binrepr(op, left, right):
"""Make specialised explanations for some operators/operands"""
left_repr = py.io.saferepr(left, maxsize=30)
@ -72,7 +79,7 @@ def pytest_assert_binrepr(op, left, right):
def _compare_eq_sequence(left, right):
explanation = []
for i in xrange(min(len(left), len(right))):
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
explanation += ['First differing item %s: %s != %s' %
(i, left[i], right[i])]

View File

@ -85,13 +85,9 @@ def test_pytest_assert_binrepr_called(monkeypatch, hook):
def test_pytest_assert_binrepr_args(monkeypatch, hook):
print hook.called
monkeypatch.setattr(py._plugin.pytest_assertion,
'pytest_assert_binrepr', hook)
interpret('assert [0, 1] == [0, 2]', getframe())
print hook.called
print hook.left
print hook.right
assert hook.op == '=='
assert hook.left == [0, 1]
assert hook.right == [0, 2]