Skip to content

Commit 4b104ba

Browse files
authored
Merge pull request #5454 from nicoddemus/backport-5446
Backport 5446
2 parents c765b83 + 4e02248 commit 4b104ba

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

changelog/5444.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``--stepwise`` mode when the first file passed on the command-line fails to collect.

src/_pytest/stepwise.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, config):
2929
self.config = config
3030
self.active = config.getvalue("stepwise")
3131
self.session = None
32+
self.report_status = ""
3233

3334
if self.active:
3435
self.lastfailed = config.cache.get("cache/stepwise", None)
@@ -70,12 +71,6 @@ def pytest_collection_modifyitems(self, session, config, items):
7071

7172
config.hook.pytest_deselected(items=already_passed)
7273

73-
def pytest_collectreport(self, report):
74-
if self.active and report.failed:
75-
self.session.shouldstop = (
76-
"Error when collecting test, stopping test execution."
77-
)
78-
7974
def pytest_runtest_logreport(self, report):
8075
# Skip this hook if plugin is not active or the test is xfailed.
8176
if not self.active or "xfail" in report.keywords:
@@ -104,7 +99,7 @@ def pytest_runtest_logreport(self, report):
10499
self.lastfailed = None
105100

106101
def pytest_report_collectionfinish(self):
107-
if self.active and self.config.getoption("verbose") >= 0:
102+
if self.active and self.config.getoption("verbose") >= 0 and self.report_status:
108103
return "stepwise: %s" % self.report_status
109104

110105
def pytest_sessionfinish(self, session):

testing/test_stepwise.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,12 @@ def test_change_testfile(stepwise_testdir):
157157
assert "test_success PASSED" in stdout
158158

159159

160-
def test_stop_on_collection_errors(broken_testdir):
161-
result = broken_testdir.runpytest(
162-
"-v",
163-
"--strict-markers",
164-
"--stepwise",
165-
"working_testfile.py",
166-
"broken_testfile.py",
167-
)
168-
169-
stdout = result.stdout.str()
170-
assert "errors during collection" in stdout
160+
@pytest.mark.parametrize("broken_first", [True, False])
161+
def test_stop_on_collection_errors(broken_testdir, broken_first):
162+
"""Stop during collection errors. Broken test first or broken test last
163+
actually surfaced a bug (#5444), so we test both situations."""
164+
files = ["working_testfile.py", "broken_testfile.py"]
165+
if broken_first:
166+
files.reverse()
167+
result = broken_testdir.runpytest("-v", "--strict-markers", "--stepwise", *files)
168+
result.stdout.fnmatch_lines("*errors during collection*")

0 commit comments

Comments
 (0)