diff --git a/_py/test/plugin/pytest_skipping.py b/_py/test/plugin/pytest_skipping.py index c87cfaa8f..e733e6b25 100644 --- a/_py/test/plugin/pytest_skipping.py +++ b/_py/test/plugin/pytest_skipping.py @@ -120,18 +120,20 @@ def pytest_runtest_setup(item): def pytest_runtest_makereport(__multicall__, item, call): if call.when != "call": return - if hasattr(item, 'obj'): - expr, result = evalexpression(item, 'xfail') - if result: - rep = __multicall__.execute() - if call.excinfo: - rep.skipped = True - rep.failed = rep.passed = False - else: - rep.skipped = rep.passed = False - rep.failed = True - rep.keywords['xfail'] = True # expr - return rep + expr, result = evalexpression(item, 'xfail') + rep = __multicall__.execute() + if result: + if call.excinfo: + rep.skipped = True + rep.failed = rep.passed = False + else: + rep.skipped = rep.passed = False + rep.failed = True + rep.keywords['xfail'] = expr + else: + if 'xfail' in rep.keywords: + del rep.keywords['xfail'] + return rep # called by terminalreporter progress reporting def pytest_report_teststatus(report): diff --git a/testing/pytest/plugin/test_pytest_skipping.py b/testing/pytest/plugin/test_pytest_skipping.py index 6fc14b9c5..74524c935 100644 --- a/testing/pytest/plugin/test_pytest_skipping.py +++ b/testing/pytest/plugin/test_pytest_skipping.py @@ -59,6 +59,20 @@ def test_xfail_at_module(testdir): ]) assert result.ret == 0 +def test_xfail_evalfalse_but_fails(testdir): + p = testdir.makepyfile(""" + import py + @py.test.mark.xfail('False') + def test_fail(): + assert 0 + """) + result = testdir.runpytest(p, '--report=xfailed') + extra = result.stdout.fnmatch_lines([ + "*test_xfail_evalfalse_but_fails*:4*", + "*1 failed*" + ]) + assert result.ret == 1 + def test_skipif_decorator(testdir): p = testdir.makepyfile(""" import py