From d4d1bf4a564d6d4be99fee5d9098910b520f6e30 Mon Sep 17 00:00:00 2001 From: henrykironde Date: Wed, 7 Nov 2018 18:09:31 -0500 Subject: [PATCH] Refactor class StepwisePlugin. Initialize class properties. Check attributes before accessing them, LBYL. --- AUTHORS | 1 + changelog/4304.bugfix.rst | 1 + src/_pytest/stepwise.py | 21 ++++++++++++--------- 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 changelog/4304.bugfix.rst diff --git a/AUTHORS b/AUTHORS index dabeb1c061c..879381e44bd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -195,6 +195,7 @@ Samuel Dion-Girardeau Samuele Pedroni Sankt Petersbug Segev Finer +Senyondo Henry Serhii Mozghovyi Simon Gomizelj Skylar Downes diff --git a/changelog/4304.bugfix.rst b/changelog/4304.bugfix.rst new file mode 100644 index 00000000000..6228c7b0a6f --- /dev/null +++ b/changelog/4304.bugfix.rst @@ -0,0 +1 @@ +Possible bug with the 3.10.0 release diff --git a/src/_pytest/stepwise.py b/src/_pytest/stepwise.py index 1efa2e7ca74..d075e65e533 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -28,10 +28,12 @@ def __init__(self, config): self.config = config self.active = config.getvalue("stepwise") self.session = None - - if self.active: - self.lastfailed = config.cache.get("cache/stepwise", None) - self.skip = config.getvalue("stepwise_skip") + self.lastfailed = None + self.skip = None + if hasattr(self.config, "cache"): + if self.active: + self.lastfailed = config.cache.get("cache/stepwise", None) + self.skip = config.getvalue("stepwise_skip") def pytest_sessionstart(self, session): self.session = session @@ -95,8 +97,9 @@ def pytest_runtest_logreport(self, report): self.lastfailed = None def pytest_sessionfinish(self, session): - if self.active: - self.config.cache.set("cache/stepwise", self.lastfailed) - else: - # Clear the list of failing tests if the plugin is not active. - self.config.cache.set("cache/stepwise", []) + if hasattr(self.config, "cache"): + if self.active: + self.config.cache.set("cache/stepwise", self.lastfailed) + else: + # Clear the list of failing tests if the plugin is not active. + self.config.cache.set("cache/stepwise", [])