@@ -226,10 +226,18 @@ def pytest_make_collect_report(self, collector: nodes.Collector):
226
226
# Sort any lf-paths to the beginning.
227
227
lf_paths = self .lfplugin ._last_failed_paths
228
228
229
+ # Use stable sort to priorize last failed.
230
+ def sort_key (node : Union [nodes .Item , nodes .Collector ]) -> bool :
231
+ # Package.path is the __init__.py file, we need the directory.
232
+ if isinstance (node , Package ):
233
+ path = node .path .parent
234
+ else :
235
+ path = node .path
236
+ return path in lf_paths
237
+
229
238
res .result = sorted (
230
239
res .result ,
231
- # use stable sort to priorize last failed
232
- key = lambda x : x .path in lf_paths ,
240
+ key = sort_key ,
233
241
reverse = True ,
234
242
)
235
243
return
@@ -272,9 +280,8 @@ def __init__(self, lfplugin: "LFPlugin") -> None:
272
280
def pytest_make_collect_report (
273
281
self , collector : nodes .Collector
274
282
) -> Optional [CollectReport ]:
275
- # Packages are Modules, but _last_failed_paths only contains
276
- # test-bearing paths and doesn't try to include the paths of their
277
- # packages, so don't filter them.
283
+ # Packages are Modules, but we only want to skip test-bearing Modules,
284
+ # so don't filter Packages.
278
285
if isinstance (collector , Module ) and not isinstance (collector , Package ):
279
286
if collector .path not in self .lfplugin ._last_failed_paths :
280
287
self .lfplugin ._skipped_files += 1
@@ -305,9 +312,14 @@ def __init__(self, config: Config) -> None:
305
312
)
306
313
307
314
def get_last_failed_paths (self ) -> Set [Path ]:
308
- """Return a set with all Paths()s of the previously failed nodeids."""
315
+ """Return a set with all Paths of the previously failed nodeids and
316
+ their parents."""
309
317
rootpath = self .config .rootpath
310
- result = {rootpath / nodeid .split ("::" )[0 ] for nodeid in self .lastfailed }
318
+ result = set ()
319
+ for nodeid in self .lastfailed :
320
+ path = rootpath / nodeid .split ("::" )[0 ]
321
+ result .add (path )
322
+ result .update (path .parents )
311
323
return {x for x in result if x .exists ()}
312
324
313
325
def pytest_report_collectionfinish (self ) -> Optional [str ]:
0 commit comments