File tree 1 file changed +15
-4
lines changed 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,14 @@ def _prepareconfig(
331
331
raise
332
332
333
333
334
+ def _get_directory (path : Path ) -> Path :
335
+ """Get the directory of a path - itself if already a directory."""
336
+ if path .is_file ():
337
+ return path .parent
338
+ else :
339
+ return path
340
+
341
+
334
342
@final
335
343
class PytestPluginManager (PluginManager ):
336
344
"""A :py:class:`pluggy.PluginManager <pluggy.PluginManager>` with
@@ -353,6 +361,12 @@ def __init__(self) -> None:
353
361
self ._conftestpath2mod : Dict [Path , types .ModuleType ] = {}
354
362
self ._confcutdir : Optional [Path ] = None
355
363
self ._noconftest = False
364
+
365
+ # _getconftestmodules()'s call to _get_directory() causes a stat
366
+ # storm when it's called potentially thousands of times in a test
367
+ # session (#9478), often with the same path, so cache it.
368
+ self ._get_directory = lru_cache (256 )(_get_directory )
369
+
356
370
self ._duplicatepaths : Set [Path ] = set ()
357
371
358
372
# plugins that were explicitly skipped with pytest.skip
@@ -530,10 +544,7 @@ def _getconftestmodules(
530
544
if self ._noconftest :
531
545
return []
532
546
533
- if path .is_file ():
534
- directory = path .parent
535
- else :
536
- directory = path
547
+ directory = self ._get_directory (path )
537
548
538
549
# Optimization: avoid repeated searches in the same directory.
539
550
# Assumes always called with same importmode and rootpath.
You can’t perform that action at this time.
0 commit comments