From 740abd9684386ff76e5557399a8a16201fa1d833 Mon Sep 17 00:00:00 2001 From: Simon K Date: Mon, 30 Aug 2021 19:24:14 +0100 Subject: [PATCH] #9062 - Allow `--stepwise-skip` to implicitly enable `--stepwise` (#9064) * #9062 - Allow `--stepwise-skip` to implicitly enable `--stepwise` * Update changelog/9062.improvement.rst Co-authored-by: Bruno Oliveira Co-authored-by: Bruno Oliveira --- changelog/9062.improvement.rst | 1 + doc/en/how-to/cache.rst | 2 +- src/_pytest/stepwise.py | 7 +++++-- testing/test_stepwise.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 changelog/9062.improvement.rst diff --git a/changelog/9062.improvement.rst b/changelog/9062.improvement.rst new file mode 100644 index 000000000..bfc7cf00a --- /dev/null +++ b/changelog/9062.improvement.rst @@ -0,0 +1 @@ +``--stepwise-skip`` now implicitly enables ``--stepwise`` and can be used on its own. diff --git a/doc/en/how-to/cache.rst b/doc/en/how-to/cache.rst index 5b1b2440d..45dc81c21 100644 --- a/doc/en/how-to/cache.rst +++ b/doc/en/how-to/cache.rst @@ -386,4 +386,4 @@ than speed. Stepwise -------- -As an alternative to ``--lf -x``, especially for cases where you expect a large part of the test suite will fail, ``--sw``, ``--stepwise`` allows you to fix them one at a time. The test suite will run until the first failure and then stop. At the next invocation, tests will continue from the last failing test and then run until the next failing test. You may use the ``--stepwise-skip`` option to ignore one failing test and stop the test execution on the second failing test instead. This is useful if you get stuck on a failing test and just want to ignore it until later. +As an alternative to ``--lf -x``, especially for cases where you expect a large part of the test suite will fail, ``--sw``, ``--stepwise`` allows you to fix them one at a time. The test suite will run until the first failure and then stop. At the next invocation, tests will continue from the last failing test and then run until the next failing test. You may use the ``--stepwise-skip`` option to ignore one failing test and stop the test execution on the second failing test instead. This is useful if you get stuck on a failing test and just want to ignore it until later. Providing ``--stepwise-skip`` will also enable ``--stepwise`` implicitly. diff --git a/src/_pytest/stepwise.py b/src/_pytest/stepwise.py index 197577c79..4d95a96b8 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -31,13 +31,16 @@ def pytest_addoption(parser: Parser) -> None: action="store_true", default=False, dest="stepwise_skip", - help="ignore the first failing test but stop on the next failing test", + help="ignore the first failing test but stop on the next failing test.\n" + "implicitly enables --stepwise.", ) @pytest.hookimpl def pytest_configure(config: Config) -> None: - # We should always have a cache as cache provider plugin uses tryfirst=True + if config.option.stepwise_skip: + # allow --stepwise-skip to work on it's own merits. + config.option.stepwise = True if config.getoption("stepwise"): config.pluginmanager.register(StepwisePlugin(config), "stepwiseplugin") diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index 85489fce8..63d29d624 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -248,3 +248,33 @@ def test_xfail_handling(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: "* 2 passed, 1 deselected, 1 xfailed in *", ] ) + + +def test_stepwise_skip_is_independent(pytester: Pytester) -> None: + pytester.makepyfile( + """ + def test_one(): + assert False + + def test_two(): + assert False + + def test_three(): + assert False + + """ + ) + result = pytester.runpytest("--tb", "no", "--stepwise-skip") + result.assert_outcomes(failed=2) + result.stdout.fnmatch_lines( + [ + "FAILED test_stepwise_skip_is_independent.py::test_one - assert False", + "FAILED test_stepwise_skip_is_independent.py::test_two - assert False", + "*Interrupted: Test failed, continuing from this test next run.*", + ] + ) + + +def test_sw_skip_help(pytester: Pytester) -> None: + result = pytester.runpytest("-h") + result.stdout.fnmatch_lines("*implicitly enables --stepwise.")