diff options
author | Ran Benita <ran@unusedvar.com> | 2020-08-18 15:45:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-18 15:45:11 +0300 |
commit | c98525bd2150573c36c2f1015e689dd1d884b0e0 (patch) | |
tree | 312c560fd0919ed10e4f9cbbb29654d0e2693e6c /src/_pytest/main.py | |
parent | afa4760cb8859c6c24c92ee8458cce329edbc206 (diff) | |
parent | eddd993cf469df33268097f4bdaf60ccb8f50d3b (diff) | |
download | pytest-c98525bd2150573c36c2f1015e689dd1d884b0e0.tar.gz |
Merge pull request #7648 from bluetech/pylint-abc2
Only define gethookproxy, isinitpath on Session
Diffstat (limited to 'src/_pytest/main.py')
-rw-r--r-- | src/_pytest/main.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/_pytest/main.py b/src/_pytest/main.py index fcc7a2dbd..2abfffba0 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -27,6 +27,7 @@ from _pytest.config import Config from _pytest.config import directory_arg from _pytest.config import ExitCode from _pytest.config import hookimpl +from _pytest.config import PytestPluginManager from _pytest.config import UsageError from _pytest.config.argparsing import Parser from _pytest.fixtures import FixtureManager @@ -390,6 +391,17 @@ def pytest_collection_modifyitems(items: List[nodes.Item], config: Config) -> No items[:] = remaining +class FSHookProxy: + def __init__(self, pm: PytestPluginManager, remove_mods) -> None: + self.pm = pm + self.remove_mods = remove_mods + + def __getattr__(self, name: str): + x = self.pm.subset_hook_caller(name, remove_plugins=self.remove_mods) + self.__dict__[name] = x + return x + + class NoMatch(Exception): """Matching cannot locate matching names.""" @@ -496,7 +508,20 @@ class Session(nodes.FSCollector): return path in self._initialpaths def gethookproxy(self, fspath: py.path.local): - return super()._gethookproxy(fspath) + # Check if we have the common case of running + # hooks with all conftest.py files. + pm = self.config.pluginmanager + my_conftestmodules = pm._getconftestmodules( + fspath, self.config.getoption("importmode") + ) + remove_mods = pm._conftest_plugins.difference(my_conftestmodules) + if remove_mods: + # One or more conftests are not in use at this fspath. + proxy = FSHookProxy(pm, remove_mods) + else: + # All plugins are active for this fspath. + proxy = self.config.hook + return proxy @overload def perform_collect( |