improve assert re-inteprpretation for comparisons
--HG-- branch : 1.0.x
This commit is contained in:
parent
9aa781907e
commit
5b205e0711
|
@ -1,6 +1,9 @@
|
||||||
Changes between 1.0.0b8 and 1.0.0b9
|
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
|
* reworked per-test output capturing into the pytest_iocapture.py plugin
|
||||||
and thus removed capturing code from config object
|
and thus removed capturing code from config object
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,10 @@ class Compare(Interpretable):
|
||||||
expr = Interpretable(self.expr)
|
expr = Interpretable(self.expr)
|
||||||
expr.eval(frame)
|
expr.eval(frame)
|
||||||
for operation, expr2 in self.ops:
|
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 = Interpretable(expr2)
|
||||||
expr2.eval(frame)
|
expr2.eval(frame)
|
||||||
self.explanation = "%s %s %s" % (
|
self.explanation = "%s %s %s" % (
|
||||||
|
@ -135,8 +139,6 @@ class Compare(Interpretable):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
raise Failure(self)
|
raise Failure(self)
|
||||||
if not frame.is_true(self.result):
|
|
||||||
break
|
|
||||||
expr = expr2
|
expr = expr2
|
||||||
|
|
||||||
class And(Interpretable):
|
class And(Interpretable):
|
||||||
|
|
|
@ -131,3 +131,26 @@ def test_inconsistent_assert_result(testdir):
|
||||||
s = result.stdout.str()
|
s = result.stdout.str()
|
||||||
assert s.find("re-run") != -1
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue