put the explanation generating code in the conditional fail body (fixes #79)
This commit is contained in:
parent
6ac638ba87
commit
29b4082b00
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue