Skip to content

Commit ca95ca1

Browse files
committed
Refactor class StepwisePlugin.
Initialize class properties. Check attributes before accessing them, LBYL.
1 parent 176d274 commit ca95ca1

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Samuel Dion-Girardeau
195195
Samuele Pedroni
196196
Sankt Petersbug
197197
Segev Finer
198+
Senyondo Henry
198199
Serhii Mozghovyi
199200
Simon Gomizelj
200201
Skylar Downes

changelog/4333.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest version 3.10.1 Fails on python2.7

src/_pytest/stepwise.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ def __init__(self, config):
2828
self.config = config
2929
self.active = config.getvalue("stepwise")
3030
self.session = None
31-
32-
if self.active:
33-
self.lastfailed = config.cache.get("cache/stepwise", None)
34-
self.skip = config.getvalue("stepwise_skip")
31+
self.lastfailed = None
32+
self.skip = None
33+
if hasattr(self.config, "cache"):
34+
if self.active:
35+
self.lastfailed = config.cache.get("cache/stepwise", None)
36+
self.skip = config.getvalue("stepwise_skip")
3537

3638
def pytest_sessionstart(self, session):
3739
self.session = session
@@ -95,8 +97,9 @@ def pytest_runtest_logreport(self, report):
9597
self.lastfailed = None
9698

9799
def pytest_sessionfinish(self, session):
98-
if self.active:
99-
self.config.cache.set("cache/stepwise", self.lastfailed)
100-
else:
101-
# Clear the list of failing tests if the plugin is not active.
102-
self.config.cache.set("cache/stepwise", [])
100+
if hasattr(self.config, "cache"):
101+
if self.active:
102+
self.config.cache.set("cache/stepwise", self.lastfailed)
103+
else:
104+
# Clear the list of failing tests if the plugin is not active.
105+
self.config.cache.set("cache/stepwise", [])

0 commit comments

Comments
 (0)