From e2fa2b621c1259e904c1ded70067d5779290422d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Jun 2019 16:45:27 -0300 Subject: [PATCH] Fix --sw crash when first file in cmdline fails to collect Fix #5444 --- changelog/5444.bugfix.rst | 1 + src/_pytest/stepwise.py | 3 ++- testing/test_stepwise.py | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 changelog/5444.bugfix.rst diff --git a/changelog/5444.bugfix.rst b/changelog/5444.bugfix.rst new file mode 100644 index 000000000..230d4b49e --- /dev/null +++ b/changelog/5444.bugfix.rst @@ -0,0 +1 @@ +Fix ``--stepwise`` mode when the first file passed on the command-line fails to collect. diff --git a/src/_pytest/stepwise.py b/src/_pytest/stepwise.py index 0427cd0ea..274f50ff0 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -29,6 +29,7 @@ class StepwisePlugin: 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) @@ -104,7 +105,7 @@ class StepwisePlugin: 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): diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index 9edd90d3d..c099fec0f 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -157,14 +157,18 @@ 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", - "broken_testfile.py", - "working_testfile.py", - ) +@pytest.mark.parametrize("broken_first", [True, False]) +def test_stop_on_collection_errors(broken_testdir, broken_first): + """Stop during collection errors. We have two possible messages depending on the order (#5444), + so test both cases.""" + files = ["working_testfile.py", "broken_testfile.py"] + if broken_first: + files.reverse() + result = broken_testdir.runpytest("-v", "--strict-markers", "--stepwise", *files) - stdout = result.stdout.str() - assert "errors during collection" in stdout + if broken_first: + result.stdout.fnmatch_lines( + "*Error when collecting test, stopping test execution*" + ) + else: + result.stdout.fnmatch_lines("*errors during collection*")