improve assert re-inteprpretation for comparisons

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-07-26 15:31:23 +02:00
parent 9aa781907e
commit 5b205e0711
3 changed files with 30 additions and 2 deletions

View File

@ -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

View File

@ -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):

View File

@ -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