fix up oversights

This commit is contained in:
Ronny Pfannschmidt 2017-03-16 11:35:00 +01:00
parent 4d31ea8316
commit 7cdefce656
5 changed files with 61 additions and 47 deletions

View File

@ -682,8 +682,9 @@ def fail_fixturefunc(fixturefunc, msg):
fs, lineno = getfslineno(fixturefunc) fs, lineno = getfslineno(fixturefunc)
location = "%s:%s" % (fs, lineno+1) location = "%s:%s" % (fs, lineno+1)
source = _pytest._code.Source(fixturefunc) source = _pytest._code.Source(fixturefunc)
pytest.fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, fail(msg + ":\n\n" + str(source.indent()) + "\n" + location,
pytrace=False) pytrace=False)
def call_fixture_func(fixturefunc, request, kwargs): def call_fixture_func(fixturefunc, request, kwargs):
yieldctx = is_generator(fixturefunc) yieldctx = is_generator(fixturefunc)

View File

@ -1223,8 +1223,8 @@ def raises(expected_exception, *args, **kwargs):
return _pytest._code.ExceptionInfo() return _pytest._code.ExceptionInfo()
fail(message) fail(message)
raises.Exception = fail.Exception
raises.Exception = fail.Exception
class RaisesContext(object): class RaisesContext(object):

View File

@ -7,7 +7,6 @@ import _pytest._code
import py import py
import sys import sys
import warnings import warnings
from _pytest.fixtures import yield_fixture from _pytest.fixtures import yield_fixture

View File

@ -204,7 +204,7 @@ def check_xfail_no_run(item):
evalxfail = item._evalxfail evalxfail = item._evalxfail
if evalxfail.istrue(): if evalxfail.istrue():
if not evalxfail.get('run', True): if not evalxfail.get('run', True):
pytest.xfail("[NOTRUN] " + evalxfail.getexplanation()) xfail("[NOTRUN] " + evalxfail.getexplanation())
def check_strict_xfail(pyfuncitem): def check_strict_xfail(pyfuncitem):
@ -216,7 +216,7 @@ def check_strict_xfail(pyfuncitem):
if is_strict_xfail: if is_strict_xfail:
del pyfuncitem._evalxfail del pyfuncitem._evalxfail
explanation = evalxfail.getexplanation() explanation = evalxfail.getexplanation()
pytest.fail('[XPASS(strict)] ' + explanation, pytrace=False) fail('[XPASS(strict)] ' + explanation, pytrace=False)
@hookimpl(hookwrapper=True) @hookimpl(hookwrapper=True)
@ -307,12 +307,14 @@ def pytest_terminal_summary(terminalreporter):
for line in lines: for line in lines:
tr._tw.line(line) tr._tw.line(line)
def show_simple(terminalreporter, lines, stat, format): def show_simple(terminalreporter, lines, stat, format):
failed = terminalreporter.stats.get(stat) failed = terminalreporter.stats.get(stat)
if failed: if failed:
for rep in failed: for rep in failed:
pos = terminalreporter.config.cwd_relative_nodeid(rep.nodeid) pos = terminalreporter.config.cwd_relative_nodeid(rep.nodeid)
lines.append(format %(pos,)) lines.append(format % (pos,))
def show_xfailed(terminalreporter, lines): def show_xfailed(terminalreporter, lines):
xfailed = terminalreporter.stats.get("xfailed") xfailed = terminalreporter.stats.get("xfailed")
@ -324,13 +326,15 @@ def show_xfailed(terminalreporter, lines):
if reason: if reason:
lines.append(" " + str(reason)) lines.append(" " + str(reason))
def show_xpassed(terminalreporter, lines): def show_xpassed(terminalreporter, lines):
xpassed = terminalreporter.stats.get("xpassed") xpassed = terminalreporter.stats.get("xpassed")
if xpassed: if xpassed:
for rep in xpassed: for rep in xpassed:
pos = terminalreporter.config.cwd_relative_nodeid(rep.nodeid) pos = terminalreporter.config.cwd_relative_nodeid(rep.nodeid)
reason = rep.wasxfail reason = rep.wasxfail
lines.append("XPASS %s %s" %(pos, reason)) lines.append("XPASS %s %s" % (pos, reason))
def cached_eval(config, expr, d): def cached_eval(config, expr, d):
if not hasattr(config, '_evalcache'): if not hasattr(config, '_evalcache'):
@ -355,6 +359,7 @@ def folded_skips(skipped):
l.append((len(events),) + key) l.append((len(events),) + key)
return l return l
def show_skipped(terminalreporter, lines): def show_skipped(terminalreporter, lines):
tr = terminalreporter tr = terminalreporter
skipped = tr.stats.get('skipped', []) skipped = tr.stats.get('skipped', [])
@ -370,5 +375,6 @@ def show_skipped(terminalreporter, lines):
for num, fspath, lineno, reason in fskips: for num, fspath, lineno, reason in fskips:
if reason.startswith("Skipped: "): if reason.startswith("Skipped: "):
reason = reason[9:] reason = reason[9:]
lines.append("SKIP [%d] %s:%d: %s" % lines.append(
"SKIP [%d] %s:%d: %s" %
(num, fspath, lineno, reason)) (num, fspath, lineno, reason))

View File

@ -2,41 +2,7 @@
""" """
pytest: unit and functional testing with Python. pytest: unit and functional testing with Python.
""" """
__all__ = [
'main',
'UsageError',
'cmdline',
'hookspec',
'hookimpl',
'__version__',
'register_assert_rewrite',
'freeze_includes',
'set_trace',
'warns',
'deprecated_call',
'fixture',
'yield_fixture',
'fail',
'skip',
'xfail',
'importorskip',
'exit',
'mark',
'_fillfuncargs',
'Item',
'File',
'Collector',
'Session',
]
if __name__ == '__main__': # if run as a script or by 'python -m pytest'
# we trigger the below "else" condition by the following import
import pytest
raise SystemExit(pytest.main())
# else we are imported # else we are imported
@ -60,10 +26,52 @@ from _pytest.python import (
Module, Class, Instance, Function, Generator, Module, Class, Instance, Function, Generator,
) )
set_trace = __pytestPDB.set_trace set_trace = __pytestPDB.set_trace
__all__ = [
'main',
'UsageError',
'cmdline',
'hookspec',
'hookimpl',
'__version__',
'register_assert_rewrite',
'freeze_includes',
'set_trace',
'warns',
'deprecated_call',
'fixture',
'yield_fixture',
'fail',
'skip',
'xfail',
'importorskip',
'exit',
'mark',
'approx',
'_fillfuncargs',
from _pytest.compat import _setup_collect_fakemodule 'Item',
_preloadplugins() # to populate pytest.* namespace so help(pytest) works 'File',
_setup_collect_fakemodule() 'Collector',
'Session',
'Module',
'Class',
'Instance',
'Function',
'Generator',
'raises',
]
if __name__ == '__main__':
# if run as a script or by 'python -m pytest'
# we trigger the below "else" condition by the following import
import pytest
raise SystemExit(pytest.main())
else:
from _pytest.compat import _setup_collect_fakemodule
_preloadplugins() # to populate pytest.* namespace so help(pytest) works
_setup_collect_fakemodule()