From d40cd3ec6b9afe563ad0ec14173ace2d665861d1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Oct 2018 18:15:55 +0200 Subject: [PATCH 1/2] Use functools.lru_cache with _getconftest_pathlist For pytest's own suite the `cache_info()` looks as follows: > session.config._getconftest_pathlist.cache_info() CacheInfo(hits=231, misses=19, maxsize=None, currsize=19) While it does not really make a difference for me this might help with larger test suites / the case mentioned in https://github.com/pytest-dev/pytest/issues/2206#issuecomment-432623646. --- src/_pytest/config/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 88cbf14ba..9769eb813 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1,6 +1,7 @@ """ command line options, ini-file and conftest.py processing. """ from __future__ import absolute_import, division, print_function import argparse +import functools import inspect import shlex import types @@ -893,6 +894,7 @@ class Config(object): assert type is None return value + @functools.lru_cache(maxsize=None) def _getconftest_pathlist(self, name, path): try: mod, relroots = self.pluginmanager._rget_with_confmod(name, path) From 1786ad16a7851cd28d1f3f2ebdbbefd30bab7177 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 24 Oct 2018 18:59:54 -0300 Subject: [PATCH 2/2] functools.lru_cache does not exist on Python 2, apply for Python 3 only --- src/_pytest/config/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 9769eb813..1c2f921a8 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -894,7 +894,6 @@ class Config(object): assert type is None return value - @functools.lru_cache(maxsize=None) def _getconftest_pathlist(self, name, path): try: mod, relroots = self.pluginmanager._rget_with_confmod(name, path) @@ -909,6 +908,10 @@ class Config(object): values.append(relroot) return values + if six.PY3: + # once we drop Python 2, please change this to use the normal decorator syntax (#4227) + _getconftest_pathlist = functools.lru_cache(maxsize=None)(_getconftest_pathlist) + def _get_override_ini_value(self, name): value = None # override_ini is a list of "ini=value" options