diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 78bf1bc04..3c7c40070 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -417,3 +417,16 @@ class FuncargnamesCompatAttr(object): def funcargnames(self): """ alias attribute for ``fixturenames`` for pre-2.3 compatibility""" return self.fixturenames + + +if six.PY2: + + def lru_cache(*_, **__): + def dec(fn): + return fn + + return dec + + +else: + from functools import lru_cache # noqa: F401 diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index bb5d2851f..5df8f2734 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1,7 +1,6 @@ """ 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 @@ -20,6 +19,7 @@ import _pytest.hookspec # the extension point definitions import _pytest.assertion from pluggy import PluginManager, HookimplMarker, HookspecMarker from _pytest._code import ExceptionInfo, filter_traceback +from _pytest.compat import lru_cache from _pytest.compat import safe_str from .exceptions import UsageError, PrintHelp from .findpaths import determine_setup, exists @@ -894,6 +894,7 @@ class Config(object): assert type is None return value + @lru_cache(maxsize=None) def _getconftest_pathlist(self, name, path): try: mod, relroots = self.pluginmanager._rget_with_confmod(name, path) @@ -908,10 +909,6 @@ 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