fix up oversights
This commit is contained in:
parent
4d31ea8316
commit
7cdefce656
|
@ -682,9 +682,10 @@ 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)
|
||||||
if yieldctx:
|
if yieldctx:
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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,6 +307,7 @@ 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:
|
||||||
|
@ -314,6 +315,7 @@ def show_simple(terminalreporter, lines, stat, format):
|
||||||
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")
|
||||||
if xfailed:
|
if xfailed:
|
||||||
|
@ -324,6 +326,7 @@ 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:
|
||||||
|
@ -332,6 +335,7 @@ def show_xpassed(terminalreporter, lines):
|
||||||
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'):
|
||||||
config._evalcache = {}
|
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))
|
||||||
|
|
78
pytest.py
78
pytest.py
|
@ -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,9 +26,51 @@ 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',
|
||||||
|
|
||||||
|
'Item',
|
||||||
|
'File',
|
||||||
|
'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
|
from _pytest.compat import _setup_collect_fakemodule
|
||||||
_preloadplugins() # to populate pytest.* namespace so help(pytest) works
|
_preloadplugins() # to populate pytest.* namespace so help(pytest) works
|
||||||
|
|
Loading…
Reference in New Issue