From f6caf230f8be2bbc7613a2f7f296340c9e2d5aa4 Mon Sep 17 00:00:00 2001 From: TomV Date: Mon, 27 Oct 2014 08:31:33 +0000 Subject: [PATCH] fix for issue615: _format_boolop must escape % fix test for issue615: expression must eval False --HG-- branch : format_boolop_percent6 --- AUTHORS | 1 + _pytest/assertion/rewrite.py | 7 ++++++- testing/test_assertrewrite.py | 12 +++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 31b7f1b80..dfa9684b1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -45,3 +45,4 @@ Andy Freeland Trevor Bekolay David Mohr Nicolas Delaby +Tom Viner diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 17157b33d..5e13a44c8 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -382,7 +382,12 @@ def _should_repr_global_name(obj): return not hasattr(obj, "__name__") and not py.builtin.callable(obj) def _format_boolop(explanations, is_or): - return "(" + (is_or and " or " or " and ").join(explanations) + ")" + explanation = "(" + (is_or and " or " or " and ").join(explanations) + ")" + if py.builtin._istext(explanation): + t = py.builtin.text + else: + t = py.builtin.bytes + return explanation.replace(t('%'), t('%%')) def _call_reprcompare(ops, results, expls, each_obj): for i, res, expl in zip(range(len(ops)), results, expls): diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 572dc6f18..56b4d3164 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -270,15 +270,13 @@ class TestAssertionRewrite: assert not 5 % 4 assert getmsg(f) == "assert not (5 % 4)" - @pytest.mark.xfail(reason='unfixed') - def test_and_or_percent(self): - # issue 615 - ValueError on compound assert with percent + def test_boolop_percent(self): def f(): - assert 3 % 2 or False - assert getmsg(f) == "assert (3 % 2) or False" + assert 3 % 2 and False + assert getmsg(f) == "assert ((3 % 2) and False)" def f(): - assert True and 7 % 3 - assert getmsg(f) == "assert True and (7 % 3)" + assert False or 4 % 2 + assert getmsg(f) == "assert (False or (4 % 2))" def test_call(self): def g(a=42, *args, **kwargs):