nice-fy error reporting of self-tests

This commit is contained in:
holger krekel 2010-11-22 15:20:18 +01:00
parent 2458c139e4
commit 6e6b0ab5d9
2 changed files with 5 additions and 2 deletions

View File

@ -125,11 +125,14 @@ class HookRecorder:
py.test.fail("could not find %r check %r" % (name, check))
def popcall(self, name):
__tracebackhide__ = True
for i, call in enumerate(self.calls):
if call._name == name:
del self.calls[i]
return call
raise ValueError("could not find call %r" %(name, ))
lines = ["could not find call %r, in:" % (name,)]
lines.extend([" %s" % str(x) for x in self.calls])
py.test.fail("\n".join(lines))
def getcall(self, name):
l = self.getcalls(name)

View File

@ -82,7 +82,7 @@ def test_hookrecorder_basic():
call = rec.popcall("pytest_xyz")
assert call.arg == 123
assert call._name == "pytest_xyz"
pytest.raises(ValueError, "rec.popcall('abc')")
pytest.raises(pytest.fail.Exception, "rec.popcall('abc')")
def test_hookrecorder_basic_no_args_hook():
rec = HookRecorder(PluginManager())