@@ -157,18 +157,11 @@ def __init__(self, config):
157
157
self .active = any (config .getoption (key ) for key in active_keys )
158
158
self .lastfailed = config .cache .get ("cache/lastfailed" , {})
159
159
self ._previously_failed_count = None
160
- self ._no_failures_behavior = self . config . getoption ( "last_failed_no_failures" )
160
+ self ._report_status = None
161
161
162
162
def pytest_report_collectionfinish (self ):
163
163
if self .active and self .config .getoption ("verbose" ) >= 0 :
164
- if not self ._previously_failed_count :
165
- return None
166
- noun = "failure" if self ._previously_failed_count == 1 else "failures"
167
- suffix = " first" if self .config .getoption ("failedfirst" ) else ""
168
- mode = "rerun previous {count} {noun}{suffix}" .format (
169
- count = self ._previously_failed_count , suffix = suffix , noun = noun
170
- )
171
- return "run-last-failure: %s" % mode
164
+ return "run-last-failure: %s" % self ._report_status
172
165
173
166
def pytest_runtest_logreport (self , report ):
174
167
if (report .when == "call" and report .passed ) or report .skipped :
@@ -196,18 +189,33 @@ def pytest_collection_modifyitems(self, session, config, items):
196
189
else :
197
190
previously_passed .append (item )
198
191
self ._previously_failed_count = len (previously_failed )
192
+
199
193
if not previously_failed :
200
- # running a subset of all tests with recorded failures outside
201
- # of the set of tests currently executing
202
- return
203
- if self .config .getoption ("lf" ):
204
- items [:] = previously_failed
205
- config .hook .pytest_deselected (items = previously_passed )
194
+ # Running a subset of all tests with recorded failures
195
+ # only outside of it.
196
+ self ._report_status = "running subset without known failures"
197
+ else :
198
+ if self .config .getoption ("lf" ):
199
+ items [:] = previously_failed
200
+ config .hook .pytest_deselected (items = previously_passed )
201
+ else : # --failedfirst
202
+ items [:] = previously_failed + previously_passed
203
+
204
+ noun = (
205
+ "failure" if self ._previously_failed_count == 1 else "failures"
206
+ )
207
+ suffix = " first" if self .config .getoption ("failedfirst" ) else ""
208
+ self ._report_status = "rerun previous {count} {noun}{suffix}" .format (
209
+ count = self ._previously_failed_count , suffix = suffix , noun = noun
210
+ )
211
+ else :
212
+ self ._report_status = "no previously failed tests, "
213
+ if self .config .getoption ("last_failed_no_failures" ) == "none" :
214
+ self ._report_status += "deselecting all items."
215
+ config .hook .pytest_deselected (items = items )
216
+ items [:] = []
206
217
else :
207
- items [:] = previously_failed + previously_passed
208
- elif self ._no_failures_behavior == "none" :
209
- config .hook .pytest_deselected (items = items )
210
- items [:] = []
218
+ self ._report_status += "not deselecting items."
211
219
212
220
def pytest_sessionfinish (self , session ):
213
221
config = self .config
@@ -303,8 +311,7 @@ def pytest_addoption(parser):
303
311
dest = "last_failed_no_failures" ,
304
312
choices = ("all" , "none" ),
305
313
default = "all" ,
306
- help = "change the behavior when no test failed in the last run or no "
307
- "information about the last failures was found in the cache" ,
314
+ help = "which tests to run with no previously (known) failures." ,
308
315
)
309
316
310
317
0 commit comments