Skip to content

Commit 16e5fbe

Browse files
committed
config: optimize PytestPluginManager._getconftestmodules
Now that it's no longer using `@lru_cache`, use another check to avoid re-computation. Although `@lru_cache` is faster than the full function call + checks, this approach also has the advantage that the caching works for more than 128 entries.
1 parent 614f539 commit 16e5fbe

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/_pytest/config/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,19 @@ def _getconftestmodules(
533533
else:
534534
directory = path
535535

536+
# Optimization: avoid repeated searches in the same directory.
537+
# Assumes always called with same importmode and rootpath.
538+
existing_clist = self._dirpath2confmods.get(directory)
539+
if existing_clist:
540+
return existing_clist
541+
536542
# XXX these days we may rather want to use config.rootpath
537543
# and allow users to opt into looking into the rootdir parent
538544
# directories instead of requiring to specify confcutdir.
539545
clist = []
546+
confcutdir_parents = self._confcutdir.parents if self._confcutdir else []
540547
for parent in reversed((directory, *directory.parents)):
541-
if self._confcutdir and parent in self._confcutdir.parents:
548+
if parent in confcutdir_parents:
542549
continue
543550
conftestpath = parent / "conftest.py"
544551
if conftestpath.is_file():

0 commit comments

Comments
 (0)