diff --git a/_pytest/setuponly.py b/_pytest/setuponly.py index 4fc472087..0ecdbc2bd 100644 --- a/_pytest/setuponly.py +++ b/_pytest/setuponly.py @@ -1,12 +1,14 @@ import pytest import sys + def pytest_addoption(parser): group = parser.getgroup("debugconfig") group.addoption('--setuponly', '--setup-only', action="store_true", - help="only setup fixtures, don't execute the tests.") + help="only setup fixtures, don't execute the tests.") group.addoption('--setupshow', '--setup-show', action="store_true", - help="show setup fixtures while executing the tests.") + help="show setup fixtures while executing the tests.") + @pytest.hookimpl(hookwrapper=True) def pytest_fixture_setup(fixturedef, request): @@ -20,11 +22,13 @@ def pytest_fixture_setup(fixturedef, request): if callable(fixturedef.ids): fixturedef.cached_param = fixturedef.ids(request.param) else: - fixturedef.cached_param = fixturedef.ids[request.param_index] + fixturedef.cached_param = fixturedef.ids[ + request.param_index] else: fixturedef.cached_param = request.param _show_fixture_action(fixturedef, 'SETUP') + def pytest_fixture_post_finalizer(fixturedef): if hasattr(fixturedef, "cached_result"): config = fixturedef._fixturemanager.config @@ -33,6 +37,7 @@ def pytest_fixture_post_finalizer(fixturedef): if hasattr(fixturedef, "cached_param"): del fixturedef.cached_param + def _show_fixture_action(fixturedef, msg): config = fixturedef._fixturemanager.config capman = config.pluginmanager.getplugin('capturemanager') @@ -60,6 +65,7 @@ def _show_fixture_action(fixturedef, msg): sys.stdout.write(out) sys.stderr.write(err) + @pytest.hookimpl(tryfirst=True) def pytest_cmdline_main(config): if config.option.setuponly: diff --git a/_pytest/setupplan.py b/_pytest/setupplan.py index 8d2d859ca..f0853dee5 100644 --- a/_pytest/setupplan.py +++ b/_pytest/setupplan.py @@ -1,10 +1,12 @@ import pytest + def pytest_addoption(parser): group = parser.getgroup("debugconfig") group.addoption('--setupplan', '--setup-plan', action="store_true", - help="show what fixtures and tests would be executed but don't" - " execute anything.") + help="show what fixtures and tests would be executed but " + "don't execute anything.") + @pytest.hookimpl(tryfirst=True) def pytest_fixture_setup(fixturedef, request): @@ -13,6 +15,7 @@ def pytest_fixture_setup(fixturedef, request): fixturedef.cached_result = (None, None, None) return fixturedef.cached_result + @pytest.hookimpl(tryfirst=True) def pytest_cmdline_main(config): if config.option.setupplan: