From 63c01d1541eda890cdb10909af09195711c8a36a Mon Sep 17 00:00:00 2001 From: David Szotten Date: Sun, 14 Oct 2018 12:58:11 +0100 Subject: [PATCH] update for builtin plugin --- src/_pytest/config/__init__.py | 1 + src/_pytest/stepwise.py | 15 +++++++-------- testing/test_stepwise.py | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 88cbf14ba..29227cc6b 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -126,6 +126,7 @@ default_plugins = ( "freeze_support", "setuponly", "setupplan", + "stepwise", "warnings", "logging", ) diff --git a/src/_pytest/stepwise.py b/src/_pytest/stepwise.py index 1f0137a46..f408e1fa9 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -1,19 +1,18 @@ -from .compat import Cache, tryfirst +from _pytest.cacheprovider import Cache +import pytest def pytest_addoption(parser): group = parser.getgroup('general') - group.addoption('--sw', action='store_true', dest='stepwise', - help='alias for --stepwise') - group.addoption('--stepwise', action='store_true', dest='stepwise', + group.addoption('--sw', '--stepwise', action='store_true', dest='stepwise', help='exit on test fail and continue from last failing test next time') - group.addoption('--skip', action='store_true', dest='skip', + group.addoption('--stepwise-skip', action='store_true', dest='stepwise_skip', help='ignore the first failing test but stop on the next failing test') -@tryfirst +@pytest.hookimpl(tryfirst=True) def pytest_configure(config): - config.cache = Cache(config) + config.cache = Cache.for_config(config) config.pluginmanager.register(StepwisePlugin(config), 'stepwiseplugin') @@ -25,7 +24,7 @@ class StepwisePlugin: if self.active: self.lastfailed = config.cache.get('cache/stepwise', None) - self.skip = config.getvalue('skip') + self.skip = config.getvalue('stepwise_skip') def pytest_sessionstart(self, session): self.session = session diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index cb52e9ead..0e1e53226 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -13,7 +13,7 @@ def pytest_addoption(parser): ''') # Create a simple test suite. - testdir.makepyfile(test_stepwise=''' + testdir.makepyfile(test_a=''' def test_success_before_fail(): assert 1 @@ -30,7 +30,7 @@ def test_success_after_last_fail(): assert 1 ''') - testdir.makepyfile(testfile_b=''' + testdir.makepyfile(test_b=''' def test_success(): assert 1 ''') @@ -40,7 +40,7 @@ def test_success(): @pytest.fixture def error_testdir(testdir): - testdir.makepyfile(test_stepwise=''' + testdir.makepyfile(test_a=''' def test_error(nonexisting_fixture): assert 1 @@ -88,7 +88,7 @@ def test_fail_and_continue_with_stepwise(stepwise_testdir): def test_run_with_skip_option(stepwise_testdir): - result = stepwise_testdir.runpytest('-v', '--strict', '--stepwise', '--skip', + result = stepwise_testdir.runpytest('-v', '--strict', '--stepwise', '--stepwise-skip', '--fail', '--fail-last') assert not result.stderr.str() @@ -112,7 +112,7 @@ def test_fail_on_errors(error_testdir): def test_change_testfile(stepwise_testdir): result = stepwise_testdir.runpytest('-v', '--strict', '--stepwise', '--fail', - 'test_stepwise.py') + 'test_a.py') assert not result.stderr.str() stdout = result.stdout.str() @@ -121,7 +121,7 @@ def test_change_testfile(stepwise_testdir): # Make sure the second test run starts from the beginning, since the # test to continue from does not exist in testfile_b. result = stepwise_testdir.runpytest('-v', '--strict', '--stepwise', - 'testfile_b.py') + 'test_b.py') assert not result.stderr.str() stdout = result.stdout.str()