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

Fix stepwise crash when first collected module fails #5446

Merged
merged 4 commits into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5444.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``--stepwise`` mode when the first file passed on the command-line fails to collect.
9 changes: 2 additions & 7 deletions src/_pytest/stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, config):
self.config = config
self.active = config.getvalue("stepwise")
self.session = None
self.report_status = ""

if self.active:
self.lastfailed = config.cache.get("cache/stepwise", None)
Expand Down Expand Up @@ -69,12 +70,6 @@ def pytest_collection_modifyitems(self, session, config, items):

config.hook.pytest_deselected(items=already_passed)

def pytest_collectreport(self, report):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed as described in bc345ac.

if self.active and report.failed:
self.session.shouldstop = (
"Error when collecting test, stopping test execution."
)

def pytest_runtest_logreport(self, report):
# Skip this hook if plugin is not active or the test is xfailed.
if not self.active or "xfail" in report.keywords:
Expand Down Expand Up @@ -103,7 +98,7 @@ def pytest_runtest_logreport(self, report):
self.lastfailed = None

def pytest_report_collectionfinish(self):
if self.active and self.config.getoption("verbose") >= 0:
if self.active and self.config.getoption("verbose") >= 0 and self.report_status:
return "stepwise: %s" % self.report_status

def pytest_sessionfinish(self, session):
Expand Down
20 changes: 9 additions & 11 deletions testing/test_stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,12 @@ def test_change_testfile(stepwise_testdir):
assert "test_success PASSED" in stdout


def test_stop_on_collection_errors(broken_testdir):
result = broken_testdir.runpytest(
"-v",
"--strict-markers",
"--stepwise",
"working_testfile.py",
"broken_testfile.py",
)

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