@@ -164,28 +164,27 @@ def __init__(self, config):
164
164
def last_failed_paths (self ):
165
165
"""Returns a set with all Paths()s of the previously failed nodeids (cached).
166
166
"""
167
- result = getattr (self , "_last_failed_paths" , None )
168
- if result is None :
167
+ try :
168
+ return self ._last_failed_paths
169
+ except AttributeError :
169
170
rootpath = Path (self .config .rootdir )
170
171
result = {rootpath / nodeid .split ("::" )[0 ] for nodeid in self .lastfailed }
172
+ result = {x for x in result if x .exists ()}
171
173
self ._last_failed_paths = result
172
- return result
174
+ return result
173
175
174
176
def pytest_ignore_collect (self , path ):
175
177
"""
176
178
Ignore this file path if we are in --lf mode and it is not in the list of
177
179
previously failed files.
178
180
"""
179
- if (
180
- self .active
181
- and self .config .getoption ("lf" )
182
- and path .isfile ()
183
- and self .lastfailed
184
- ):
185
- skip_it = Path (path ) not in self .last_failed_paths ()
186
- if skip_it :
187
- self ._skipped_files += 1
188
- return skip_it
181
+ if self .active and self .config .getoption ("lf" ) and path .isfile ():
182
+ last_failed_paths = self .last_failed_paths ()
183
+ if last_failed_paths :
184
+ skip_it = Path (path ) not in self .last_failed_paths ()
185
+ if skip_it :
186
+ self ._skipped_files += 1
187
+ return skip_it
189
188
190
189
def pytest_report_collectionfinish (self ):
191
190
if self .active and self .config .getoption ("verbose" ) >= 0 :
@@ -234,19 +233,15 @@ def pytest_collection_modifyitems(self, session, config, items):
234
233
items [:] = previously_failed + previously_passed
235
234
236
235
noun = "failure" if self ._previously_failed_count == 1 else "failures"
237
- if self ._skipped_files > 0 :
238
- files_noun = "file" if self ._skipped_files == 1 else "files"
239
- skipped_files_msg = " (skipped {files} {files_noun})" .format (
240
- files = self ._skipped_files , files_noun = files_noun
241
- )
242
- else :
243
- skipped_files_msg = ""
244
236
suffix = " first" if self .config .getoption ("failedfirst" ) else ""
245
- self ._report_status = "rerun previous {count} {noun}{suffix}{skipped_files}" .format (
246
- count = self ._previously_failed_count ,
247
- suffix = suffix ,
248
- noun = noun ,
249
- skipped_files = skipped_files_msg ,
237
+ self ._report_status = "rerun previous {count} {noun}{suffix}" .format (
238
+ count = self ._previously_failed_count , suffix = suffix , noun = noun
239
+ )
240
+
241
+ if self ._skipped_files > 0 :
242
+ files_noun = "file" if self ._skipped_files == 1 else "files"
243
+ self ._report_status += " (skipped {files} {files_noun})" .format (
244
+ files = self ._skipped_files , files_noun = files_noun
250
245
)
251
246
else :
252
247
self ._report_status = "no previously failed tests, "
0 commit comments