Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9062 - Allow --stepwise-skip to implicitly enable --stepwise #9064

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/9062.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``--stepwise-skip`` now implicitly enables ``--stepwise`` and can be used on it's own.
symonk marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion doc/en/how-to/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 5 additions & 2 deletions src/_pytest/stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
30 changes: 30 additions & 0 deletions testing/test_stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,33 @@ def test_d(): pass
"* 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.")