Treat unittest.expectedFailure pass as a failure

This commit is contained in:
Raphael Pierzina 2016-08-12 23:18:36 +01:00
parent 10a6ed1707
commit 296f42a2c9
1 changed files with 7 additions and 4 deletions

View File

@ -228,10 +228,13 @@ def pytest_runtest_makereport(item, call):
evalskip = getattr(item, '_evalskip', None) evalskip = getattr(item, '_evalskip', None)
# unitttest special case, see setting of _unexpectedsuccess # unitttest special case, see setting of _unexpectedsuccess
if hasattr(item, '_unexpectedsuccess') and rep.when == "call": if hasattr(item, '_unexpectedsuccess') and rep.when == "call":
# we need to translate into how pytest encodes xpass # unittest treats an 'unexpected successes' as a failure
rep.wasxfail = "reason: " + repr(item._unexpectedsuccess) # which means pytest needs to handle it like a 'xfail(strict=True)'
# TODO: Do we need to check for strict xfail here as well? rep.outcome = "failed"
rep.outcome = "passed" if item._unexpectedsuccess:
rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess)
else:
rep.longrepr = "Unexpected success"
elif item.config.option.runxfail: elif item.config.option.runxfail:
pass # don't interefere pass # don't interefere
elif call.excinfo and call.excinfo.errisinstance(pytest.xfail.Exception): elif call.excinfo and call.excinfo.errisinstance(pytest.xfail.Exception):