From 56b955dfb572e2e76006bb69893c58e8b9d67028 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Wed, 22 Sep 2010 18:42:04 +0100 Subject: [PATCH] Make pytest_assert_binrepr work on python3 too --HG-- branch : trunk --- py/_plugin/pytest_assertion.py | 9 ++++++++- testing/plugin/test_pytest_assertion.py | 4 ---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/py/_plugin/pytest_assertion.py b/py/_plugin/pytest_assertion.py index 347f7edb7..226da79c7 100644 --- a/py/_plugin/pytest_assertion.py +++ b/py/_plugin/pytest_assertion.py @@ -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])] diff --git a/testing/plugin/test_pytest_assertion.py b/testing/plugin/test_pytest_assertion.py index 81796dd12..9d750896f 100644 --- a/testing/plugin/test_pytest_assertion.py +++ b/testing/plugin/test_pytest_assertion.py @@ -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]