diff --git a/CHANGELOG b/CHANGELOG index 12e13fca5..4243815d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Changes between 2.1.2 and [next version] ---------------------------------------- +- fix issue79: rewriting failed on some comparisons in boolops - correctly handle zero length arguments (a la pytest '') - fix issue67 / junitxml now contains correct test durations, thanks ronny - fix issue75 / skipping test failure on jython diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 3dfa66321..aa4ffe140 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -491,13 +491,13 @@ class AssertionRewriter(ast.NodeVisitor): self.push_format_context() # Process each operand, short-circuting if needed. for i, v in enumerate(boolop.values): - self.push_format_context() - res, expl = self.visit(v) - body.append(ast.Assign([ast.Name(res_var, ast.Store())], res)) if i: fail_inner = [] self.on_failure.append(ast.If(cond, fail_inner, [])) self.on_failure = fail_inner + self.push_format_context() + res, expl = self.visit(v) + body.append(ast.Assign([ast.Name(res_var, ast.Store())], res)) expl_format = self.pop_format_context(ast.Str(expl)) call = ast.Call(app, [expl_format], [], None, None) self.on_failure.append(ast.Expr(call)) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 82fd08f62..c07f10dae 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -144,6 +144,14 @@ class TestAssertionRewrite: def f(): assert False or x() assert getmsg(f, {"x" : x}) == "assert (False or x())" + def f(): + assert 1 in {} and 2 in {} + assert getmsg(f) == "assert (1 in {})" + def f(): + x = 1 + y = 2 + assert x in {1 : None} and y in {} + assert getmsg(f) == "assert (1 in {1: None} and 2 in {})" def f(): f = True g = False