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.
This commit is contained in:
parent
614f5394b5
commit
16e5fbe371
|
@ -533,12 +533,19 @@ class PytestPluginManager(PluginManager):
|
||||||
else:
|
else:
|
||||||
directory = path
|
directory = path
|
||||||
|
|
||||||
|
# Optimization: avoid repeated searches in the same directory.
|
||||||
|
# Assumes always called with same importmode and rootpath.
|
||||||
|
existing_clist = self._dirpath2confmods.get(directory)
|
||||||
|
if existing_clist:
|
||||||
|
return existing_clist
|
||||||
|
|
||||||
# XXX these days we may rather want to use config.rootpath
|
# XXX these days we may rather want to use config.rootpath
|
||||||
# and allow users to opt into looking into the rootdir parent
|
# and allow users to opt into looking into the rootdir parent
|
||||||
# directories instead of requiring to specify confcutdir.
|
# directories instead of requiring to specify confcutdir.
|
||||||
clist = []
|
clist = []
|
||||||
|
confcutdir_parents = self._confcutdir.parents if self._confcutdir else []
|
||||||
for parent in reversed((directory, *directory.parents)):
|
for parent in reversed((directory, *directory.parents)):
|
||||||
if self._confcutdir and parent in self._confcutdir.parents:
|
if parent in confcutdir_parents:
|
||||||
continue
|
continue
|
||||||
conftestpath = parent / "conftest.py"
|
conftestpath = parent / "conftest.py"
|
||||||
if conftestpath.is_file():
|
if conftestpath.is_file():
|
||||||
|
|
Loading…
Reference in New Issue