Fix stepwise crash when first collected module fails (#5446)

Fix stepwise crash when first collected module fails
This commit is contained in:
Bruno Oliveira 2019-06-16 10:43:18 -03:00 committed by GitHub
commit b38a4e8e11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 18 deletions

View File

@ -0,0 +1 @@
Fix ``--stepwise`` mode when the first file passed on the command-line fails to collect.

View File

@ -28,6 +28,7 @@ class StepwisePlugin:
self.config = config self.config = config
self.active = config.getvalue("stepwise") self.active = config.getvalue("stepwise")
self.session = None self.session = None
self.report_status = ""
if self.active: if self.active:
self.lastfailed = config.cache.get("cache/stepwise", None) self.lastfailed = config.cache.get("cache/stepwise", None)
@ -69,12 +70,6 @@ class StepwisePlugin:
config.hook.pytest_deselected(items=already_passed) config.hook.pytest_deselected(items=already_passed)
def pytest_collectreport(self, report):
if self.active and report.failed:
self.session.shouldstop = (
"Error when collecting test, stopping test execution."
)
def pytest_runtest_logreport(self, report): def pytest_runtest_logreport(self, report):
# Skip this hook if plugin is not active or the test is xfailed. # Skip this hook if plugin is not active or the test is xfailed.
if not self.active or "xfail" in report.keywords: if not self.active or "xfail" in report.keywords:
@ -103,7 +98,7 @@ class StepwisePlugin:
self.lastfailed = None self.lastfailed = None
def pytest_report_collectionfinish(self): 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 return "stepwise: %s" % self.report_status
def pytest_sessionfinish(self, session): def pytest_sessionfinish(self, session):

View File

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