fix issue91 introduce new py.test.xfail(reason) helper

to imperatively mark a test as expected to fail. Can
be used from within setup and test functions. This is
useful especially for parametrized tests when certain
configurations are expected-to-fail.  In this case the
declarative approach with the @py.test.mark.xfail cannot
be used as it would mark all configurations as xfail.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2010-05-20 13:29:51 +02:00
parent eac0345689
commit 925f75088d
4 changed files with 69 additions and 3 deletions

View File

@@ -185,9 +185,17 @@ def pytest_runtest_setup(item):
def pytest_runtest_makereport(__multicall__, item, call):
if not isinstance(item, py.test.collect.Function):
return
evalxfail = getattr(item, '_evalxfail', None)
if not evalxfail:
return
if not (call.excinfo and
call.excinfo.errisinstance(py.test.xfail.Exception)):
evalxfail = getattr(item, '_evalxfail', None)
if not evalxfail:
return
if call.excinfo and call.excinfo.errisinstance(py.test.xfail.Exception):
rep = __multicall__.execute()
rep.keywords['xfail'] = "reason: " + call.excinfo.value.msg
rep.skipped = True
rep.failed = False
return rep
if call.when == "setup":
rep = __multicall__.execute()
if rep.skipped and evalxfail.istrue():