From 0fc11b6f3cd060b10e236269118182df80d036a9 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 13 Jun 2019 12:38:33 +0100 Subject: [PATCH 1/4] add test for stepwise attribute error Refs: #5444 --- testing/test_stepwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index 68e5989ecdb..9edd90d3d69 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -162,8 +162,8 @@ def test_stop_on_collection_errors(broken_testdir): "-v", "--strict-markers", "--stepwise", - "working_testfile.py", "broken_testfile.py", + "working_testfile.py", ) stdout = result.stdout.str() From e2fa2b621c1259e904c1ded70067d5779290422d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Jun 2019 16:45:27 -0300 Subject: [PATCH 2/4] 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 | 26 +++++++++++++++----------- 3 files changed, 18 insertions(+), 12 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 00000000000..230d4b49eb6 --- /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 0427cd0ea45..274f50ff0cc 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -29,6 +29,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) @@ -104,7 +105,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): diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index 9edd90d3d69..c099fec0f58 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", - ) - - 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. 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) + + if broken_first: + result.stdout.fnmatch_lines( + "*Error when collecting test, stopping test execution*" + ) + else: + result.stdout.fnmatch_lines("*errors during collection*") From 43a499e6fa02436104f239f736b8ac837c200128 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Jun 2019 17:19:36 -0300 Subject: [PATCH 3/4] Remove handling of collection errors by --sw Since then pytest itself adopted the behavior of interrupting the test session on collection errors, so --sw no longer needs to handle this. The --sw behavior seems have been implemented when pytest would continue execution even if there were collection errors. --- src/_pytest/stepwise.py | 6 ------ testing/test_stepwise.py | 8 +------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/_pytest/stepwise.py b/src/_pytest/stepwise.py index 274f50ff0cc..81b9fa0f433 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -71,12 +71,6 @@ def pytest_collection_modifyitems(self, session, config, items): 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): # Skip this hook if plugin is not active or the test is xfailed. if not self.active or "xfail" in report.keywords: diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index c099fec0f58..3b799a830d0 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -165,10 +165,4 @@ def test_stop_on_collection_errors(broken_testdir, broken_first): if broken_first: files.reverse() result = broken_testdir.runpytest("-v", "--strict-markers", "--stepwise", *files) - - if broken_first: - result.stdout.fnmatch_lines( - "*Error when collecting test, stopping test execution*" - ) - else: - result.stdout.fnmatch_lines("*errors during collection*") + result.stdout.fnmatch_lines("*errors during collection*") From 4e02248b84bdbb48af9c3fa5ba06b690ca6ae8e1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Jun 2019 23:10:13 -0300 Subject: [PATCH 4/4] Fix test docstring --- testing/test_stepwise.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index 3b799a830d0..b27dd02993e 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -159,8 +159,8 @@ def test_change_testfile(stepwise_testdir): @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.""" + """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()