2009-02-27 18:18:27 +08:00
|
|
|
"""
|
2009-05-21 05:12:37 +08:00
|
|
|
mark tests as expected-to-fail and report them separately.
|
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
example::
|
2009-05-19 05:26:16 +08:00
|
|
|
|
2009-06-28 19:27:34 +08:00
|
|
|
@py.test.mark.xfail
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_hello():
|
|
|
|
...
|
|
|
|
assert 0
|
|
|
|
"""
|
|
|
|
import py
|
|
|
|
|
2009-06-28 19:27:34 +08:00
|
|
|
pytest_plugins = ['keyword']
|
|
|
|
|
2009-06-09 22:08:34 +08:00
|
|
|
def pytest_runtest_makereport(__call__, item, call):
|
|
|
|
if call.when != "call":
|
|
|
|
return
|
2009-05-19 05:26:16 +08:00
|
|
|
if hasattr(item, 'obj') and hasattr(item.obj, 'func_dict'):
|
|
|
|
if 'xfail' in item.obj.func_dict:
|
|
|
|
res = __call__.execute(firstresult=True)
|
2009-06-09 22:08:34 +08:00
|
|
|
if call.excinfo:
|
2009-05-19 05:26:16 +08:00
|
|
|
res.skipped = True
|
|
|
|
res.failed = res.passed = False
|
|
|
|
else:
|
|
|
|
res.skipped = res.passed = False
|
|
|
|
res.failed = True
|
|
|
|
return res
|
2009-03-07 02:07:44 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_report_teststatus(rep):
|
|
|
|
""" return shortletter and verbose word. """
|
|
|
|
if 'xfail' in rep.keywords:
|
|
|
|
if rep.skipped:
|
|
|
|
return "xfailed", "x", "xfail"
|
|
|
|
elif rep.failed:
|
|
|
|
return "xpassed", "P", "xpass"
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-05-21 05:12:37 +08:00
|
|
|
# called by the terminalreporter instance/plugin
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_terminal_summary(terminalreporter):
|
|
|
|
tr = terminalreporter
|
|
|
|
xfailed = tr.stats.get("xfailed")
|
|
|
|
if xfailed:
|
|
|
|
tr.write_sep("_", "expected failures")
|
|
|
|
for event in xfailed:
|
|
|
|
entry = event.longrepr.reprcrash
|
|
|
|
key = entry.path, entry.lineno, entry.message
|
|
|
|
reason = event.longrepr.reprcrash.message
|
2009-05-23 01:56:05 +08:00
|
|
|
modpath = event.item.getmodpath(includemodule=True)
|
2009-05-19 05:26:16 +08:00
|
|
|
#tr._tw.line("%s %s:%d: %s" %(modpath, entry.path, entry.lineno, entry.message))
|
|
|
|
tr._tw.line("%s %s:%d: " %(modpath, entry.path, entry.lineno))
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
xpassed = terminalreporter.stats.get("xpassed")
|
|
|
|
if xpassed:
|
|
|
|
tr.write_sep("_", "UNEXPECTEDLY PASSING TESTS")
|
|
|
|
for event in xpassed:
|
2009-05-23 01:56:05 +08:00
|
|
|
tr._tw.line("%s: xpassed" %(event.item,))
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-06-18 23:19:12 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
# ===============================================================================
|
|
|
|
#
|
|
|
|
# plugin tests
|
|
|
|
#
|
|
|
|
# ===============================================================================
|
|
|
|
|
2009-05-23 05:50:35 +08:00
|
|
|
def test_xfail(testdir, linecomp):
|
2009-02-27 18:18:27 +08:00
|
|
|
p = testdir.makepyfile(test_one="""
|
|
|
|
import py
|
2009-06-28 19:27:34 +08:00
|
|
|
@py.test.mark.xfail
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_this():
|
|
|
|
assert 0
|
2009-03-07 02:07:44 +08:00
|
|
|
|
2009-06-28 19:27:34 +08:00
|
|
|
@py.test.mark.xfail
|
2009-03-07 02:07:44 +08:00
|
|
|
def test_that():
|
|
|
|
assert 1
|
2009-02-27 18:18:27 +08:00
|
|
|
""")
|
|
|
|
result = testdir.runpytest(p)
|
|
|
|
extra = result.stdout.fnmatch_lines([
|
2009-03-07 02:07:44 +08:00
|
|
|
"*expected failures*",
|
2009-06-18 23:19:12 +08:00
|
|
|
"*test_one.test_this*test_one.py:4*",
|
2009-03-07 02:07:44 +08:00
|
|
|
"*UNEXPECTEDLY PASSING*",
|
|
|
|
"*test_that*",
|
2009-02-27 18:18:27 +08:00
|
|
|
])
|
|
|
|
assert result.ret == 1
|