Skip to content

Commit 296f42a

Browse files
committed
Treat unittest.expectedFailure pass as a failure
1 parent 10a6ed1 commit 296f42a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

_pytest/skipping.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,13 @@ def pytest_runtest_makereport(item, call):
228228
evalskip = getattr(item, '_evalskip', None)
229229
# unitttest special case, see setting of _unexpectedsuccess
230230
if hasattr(item, '_unexpectedsuccess') and rep.when == "call":
231-
# we need to translate into how pytest encodes xpass
232-
rep.wasxfail = "reason: " + repr(item._unexpectedsuccess)
233-
# TODO: Do we need to check for strict xfail here as well?
234-
rep.outcome = "passed"
231+
# unittest treats an 'unexpected successes' as a failure
232+
# which means pytest needs to handle it like a 'xfail(strict=True)'
233+
rep.outcome = "failed"
234+
if item._unexpectedsuccess:
235+
rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess)
236+
else:
237+
rep.longrepr = "Unexpected success"
235238
elif item.config.option.runxfail:
236239
pass # don't interefere
237240
elif call.excinfo and call.excinfo.errisinstance(pytest.xfail.Exception):

0 commit comments

Comments
 (0)