summaryrefslogtreecommitdiff
path: root/src/_pytest/main.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-08-15 11:35:54 +0300
committerRan Benita <ran@unusedvar.com>2020-08-15 13:40:16 +0300
commiteddd993cf469df33268097f4bdaf60ccb8f50d3b (patch)
tree1d8b3a7d37ec8b77432e2443c79d95bc703232ab /src/_pytest/main.py
parentd426a79a90351dff0492fbd40404b1256b24f91f (diff)
downloadpytest-eddd993cf469df33268097f4bdaf60ccb8f50d3b.tar.gz
Only define gethookproxy, isinitpath on Session
This fixes an issue where pylint complains about missing implementations of abstract methods in subclasses of `File` which only override `collect()` (as they should). It is also cleaner and makes sense, these methods really don't need to be overridden. The previous methods defined directly on `FSCollector` and `Package` are deprecated, to be removed in pytest 7. See commits e2934c3f8c03c83469f4c6670c207773a6e02df4 and f10ab021e21a44e2f0fa2be66660c4a6d4b7a61a for reference.
Diffstat (limited to 'src/_pytest/main.py')
-rw-r--r--src/_pytest/main.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/_pytest/main.py b/src/_pytest/main.py
index 0baa22a6a..58d45ebd1 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
@@ -389,6 +390,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."""
@@ -495,7 +507,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(