diff --git a/CHANGELOG b/CHANGELOG index 1ed977434..0538a5abe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 1.0.0b8 and 1.0.0b9 ===================================== +* make assert-reinterpretation work better with comparisons not + returning bools (reported with numpy from thanks maciej fijalkowski) + * reworked per-test output capturing into the pytest_iocapture.py plugin and thus removed capturing code from config object diff --git a/py/magic/exprinfo.py b/py/magic/exprinfo.py index 2161c52a7..369e759d5 100644 --- a/py/magic/exprinfo.py +++ b/py/magic/exprinfo.py @@ -122,6 +122,10 @@ class Compare(Interpretable): expr = Interpretable(self.expr) expr.eval(frame) for operation, expr2 in self.ops: + if hasattr(self, 'result'): + # shortcutting in chained expressions + if not frame.is_true(self.result): + break expr2 = Interpretable(expr2) expr2.eval(frame) self.explanation = "%s %s %s" % ( @@ -135,8 +139,6 @@ class Compare(Interpretable): raise except: raise Failure(self) - if not frame.is_true(self.result): - break expr = expr2 class And(Interpretable): diff --git a/py/magic/testing/test_exprinfo.py b/py/magic/testing/test_exprinfo.py index 636997745..666460e83 100644 --- a/py/magic/testing/test_exprinfo.py +++ b/py/magic/testing/test_exprinfo.py @@ -131,3 +131,26 @@ def test_inconsistent_assert_result(testdir): s = result.stdout.str() assert s.find("re-run") != -1 +def test_twoarg_comparison_does_not_call_nonzero(): + # this arises e.g. in numpy array comparisons + class X(object): + def __eq__(self, other): + return self + + def __nonzero__(self): + raise ValueError + + def all(self): + return False + + def f(): + a = X() + b = X() + assert (a == b).all() + + excinfo = getexcinfo(AssertionError, f) + msg = getmsg(excinfo) + print msg + assert "re-run" not in msg + assert "ValueError" not in msg +