File tree 1 file changed +14
-4
lines changed 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -330,6 +330,14 @@ def _prepareconfig(
330
330
raise
331
331
332
332
333
+ def _get_directory (path : Path ) -> Path :
334
+ """Get the directory of a path - itself if already a directory."""
335
+ if path .is_file ():
336
+ return path .parent
337
+ else :
338
+ return path
339
+
340
+
333
341
@final
334
342
class PytestPluginManager (PluginManager ):
335
343
"""A :py:class:`pluggy.PluginManager <pluggy.PluginManager>` with
@@ -357,6 +365,11 @@ def __init__(self) -> None:
357
365
# If set, conftest loading is skipped.
358
366
self ._noconftest = False
359
367
368
+ # _getconftestmodules()'s call to _get_directory() causes a stat
369
+ # storm when it's called potentially thousands of times in a test
370
+ # session (#9478), often with the same path, so cache it.
371
+ self ._get_directory = lru_cache (256 )(_get_directory )
372
+
360
373
self ._duplicatepaths : Set [Path ] = set ()
361
374
362
375
# plugins that were explicitly skipped with pytest.skip
@@ -547,10 +560,7 @@ def _getconftestmodules(
547
560
if self ._noconftest :
548
561
return []
549
562
550
- if path .is_file ():
551
- directory = path .parent
552
- else :
553
- directory = path
563
+ directory = self ._get_directory (path )
554
564
555
565
# Optimization: avoid repeated searches in the same directory.
556
566
# Assumes always called with same importmode and rootpath.
You can’t perform that action at this time.
0 commit comments