Skip to content

Commit 740abd9

Browse files
symonknicoddemus
andauthored
#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 <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent af42e71 commit 740abd9

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

changelog/9062.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``--stepwise-skip`` now implicitly enables ``--stepwise`` and can be used on its own.

doc/en/how-to/cache.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,4 @@ than speed.
386386
Stepwise
387387
--------
388388

389-
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.
389+
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.

src/_pytest/stepwise.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ def pytest_addoption(parser: Parser) -> None:
3131
action="store_true",
3232
default=False,
3333
dest="stepwise_skip",
34-
help="ignore the first failing test but stop on the next failing test",
34+
help="ignore the first failing test but stop on the next failing test.\n"
35+
"implicitly enables --stepwise.",
3536
)
3637

3738

3839
@pytest.hookimpl
3940
def pytest_configure(config: Config) -> None:
40-
# We should always have a cache as cache provider plugin uses tryfirst=True
41+
if config.option.stepwise_skip:
42+
# allow --stepwise-skip to work on it's own merits.
43+
config.option.stepwise = True
4144
if config.getoption("stepwise"):
4245
config.pluginmanager.register(StepwisePlugin(config), "stepwiseplugin")
4346

testing/test_stepwise.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,33 @@ def test_d(): pass
248248
"* 2 passed, 1 deselected, 1 xfailed in *",
249249
]
250250
)
251+
252+
253+
def test_stepwise_skip_is_independent(pytester: Pytester) -> None:
254+
pytester.makepyfile(
255+
"""
256+
def test_one():
257+
assert False
258+
259+
def test_two():
260+
assert False
261+
262+
def test_three():
263+
assert False
264+
265+
"""
266+
)
267+
result = pytester.runpytest("--tb", "no", "--stepwise-skip")
268+
result.assert_outcomes(failed=2)
269+
result.stdout.fnmatch_lines(
270+
[
271+
"FAILED test_stepwise_skip_is_independent.py::test_one - assert False",
272+
"FAILED test_stepwise_skip_is_independent.py::test_two - assert False",
273+
"*Interrupted: Test failed, continuing from this test next run.*",
274+
]
275+
)
276+
277+
278+
def test_sw_skip_help(pytester: Pytester) -> None:
279+
result = pytester.runpytest("-h")
280+
result.stdout.fnmatch_lines("*implicitly enables --stepwise.")

0 commit comments

Comments
 (0)