From 09ba42a1bb85271f56b0ab558da87905e0dd4fd9 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 27 Oct 2009 12:02:40 +0100 Subject: [PATCH] fix bug: a false xfail expression would erranonously report XPASS on failures --HG-- branch : trunk --- _py/test/plugin/pytest_skipping.py | 26 ++++++++++--------- testing/pytest/plugin/test_pytest_skipping.py | 14 ++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) 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