summaryrefslogtreecommitdiff
path: root/_pytest
diff options
context:
space:
mode:
authorBrian Maissy <brian.maissy@gmail.com>2018-02-21 01:27:24 +0200
committerBrian Maissy <brian.maissy@gmail.com>2018-03-10 21:20:12 +0200
commit54b15f5826438a311c22c693bdb248ed5f379e97 (patch)
tree4ca64ad4c0da24ce5fdb46bc5ce9f3015525362b /_pytest
parentd6ddeb395bbf788a708c90f6e3003fb57cdc3b7e (diff)
downloadpytest-54b15f5826438a311c22c693bdb248ed5f379e97.tar.gz
deprecated pytest_plugins in non-top-level conftest
Diffstat (limited to '_pytest')
-rw-r--r--_pytest/config.py6
-rw-r--r--_pytest/deprecated.py6
2 files changed, 12 insertions, 0 deletions
diff --git a/_pytest/config.py b/_pytest/config.py
index cdd996896..b99b1bbcb 100644
--- a/_pytest/config.py
+++ b/_pytest/config.py
@@ -201,6 +201,8 @@ class PytestPluginManager(PluginManager):
# Config._consider_importhook will set a real object if required.
self.rewrite_hook = _pytest.assertion.DummyRewriteHook()
+ # Used to know when we are importing conftests after the pytest_configure stage
+ self._configured = False
def addhooks(self, module_or_class):
"""
@@ -276,6 +278,7 @@ class PytestPluginManager(PluginManager):
config.addinivalue_line("markers",
"trylast: mark a hook implementation function such that the "
"plugin machinery will try to call it last/as late as possible.")
+ self._configured = True
def _warn(self, message):
kwargs = message if isinstance(message, dict) else {
@@ -366,6 +369,9 @@ class PytestPluginManager(PluginManager):
_ensure_removed_sysmodule(conftestpath.purebasename)
try:
mod = conftestpath.pyimport()
+ if hasattr(mod, 'pytest_plugins') and self._configured:
+ from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
+ warnings.warn(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST)
except Exception:
raise ConftestImportFailure(conftestpath, sys.exc_info())
diff --git a/_pytest/deprecated.py b/_pytest/deprecated.py
index 1eae354b3..a0eec0e7d 100644
--- a/_pytest/deprecated.py
+++ b/_pytest/deprecated.py
@@ -56,3 +56,9 @@ METAFUNC_ADD_CALL = (
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
"Please use Metafunc.parametrize instead."
)
+
+PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
+ "Defining pytest_plugins in a non-top-level conftest is deprecated, "
+ "because it affects the entire directory tree in a non-explicit way.\n"
+ "Please move it to the top level conftest file instead."
+)