diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index 2710da792..714a8b406 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -682,8 +682,9 @@ def fail_fixturefunc(fixturefunc, msg): fs, lineno = getfslineno(fixturefunc) location = "%s:%s" % (fs, lineno+1) source = _pytest._code.Source(fixturefunc) - pytest.fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, - pytrace=False) + fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, + pytrace=False) + def call_fixture_func(fixturefunc, request, kwargs): yieldctx = is_generator(fixturefunc) diff --git a/_pytest/python.py b/_pytest/python.py index 985b476ca..4f33a356b 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1223,8 +1223,8 @@ def raises(expected_exception, *args, **kwargs): return _pytest._code.ExceptionInfo() fail(message) -raises.Exception = fail.Exception +raises.Exception = fail.Exception class RaisesContext(object): diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index 73325cb8e..7dce842f6 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -7,7 +7,6 @@ import _pytest._code import py import sys import warnings - from _pytest.fixtures import yield_fixture diff --git a/_pytest/skipping.py b/_pytest/skipping.py index c68cdea47..e7922da7d 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -204,7 +204,7 @@ def check_xfail_no_run(item): evalxfail = item._evalxfail if evalxfail.istrue(): if not evalxfail.get('run', True): - pytest.xfail("[NOTRUN] " + evalxfail.getexplanation()) + xfail("[NOTRUN] " + evalxfail.getexplanation()) def check_strict_xfail(pyfuncitem): @@ -216,7 +216,7 @@ def check_strict_xfail(pyfuncitem): if is_strict_xfail: del pyfuncitem._evalxfail explanation = evalxfail.getexplanation() - pytest.fail('[XPASS(strict)] ' + explanation, pytrace=False) + fail('[XPASS(strict)] ' + explanation, pytrace=False) @hookimpl(hookwrapper=True) @@ -307,12 +307,14 @@ def pytest_terminal_summary(terminalreporter): for line in lines: tr._tw.line(line) + def show_simple(terminalreporter, lines, stat, format): failed = terminalreporter.stats.get(stat) if failed: for rep in failed: pos = terminalreporter.config.cwd_relative_nodeid(rep.nodeid) - lines.append(format %(pos,)) + lines.append(format % (pos,)) + def show_xfailed(terminalreporter, lines): xfailed = terminalreporter.stats.get("xfailed") @@ -324,13 +326,15 @@ def show_xfailed(terminalreporter, lines): if reason: lines.append(" " + str(reason)) + def show_xpassed(terminalreporter, lines): xpassed = terminalreporter.stats.get("xpassed") if xpassed: for rep in xpassed: pos = terminalreporter.config.cwd_relative_nodeid(rep.nodeid) reason = rep.wasxfail - lines.append("XPASS %s %s" %(pos, reason)) + lines.append("XPASS %s %s" % (pos, reason)) + def cached_eval(config, expr, d): if not hasattr(config, '_evalcache'): @@ -355,6 +359,7 @@ def folded_skips(skipped): l.append((len(events),) + key) return l + def show_skipped(terminalreporter, lines): tr = terminalreporter skipped = tr.stats.get('skipped', []) @@ -370,5 +375,6 @@ def show_skipped(terminalreporter, lines): for num, fspath, lineno, reason in fskips: if reason.startswith("Skipped: "): reason = reason[9:] - lines.append("SKIP [%d] %s:%d: %s" % + lines.append( + "SKIP [%d] %s:%d: %s" % (num, fspath, lineno, reason)) diff --git a/pytest.py b/pytest.py index 8185d6503..d720ee866 100644 --- a/pytest.py +++ b/pytest.py @@ -2,41 +2,7 @@ """ 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 @@ -60,10 +26,52 @@ from _pytest.python import ( Module, Class, Instance, Function, Generator, ) - 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 -_preloadplugins() # to populate pytest.* namespace so help(pytest) works -_setup_collect_fakemodule() \ No newline at end of file + '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 + _preloadplugins() # to populate pytest.* namespace so help(pytest) works + _setup_collect_fakemodule()