diff --git a/doc/en/reference.rst b/doc/en/reference.rst index da53e7fea91..d8b209c067f 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -878,8 +878,8 @@ Contains comma-separated list of modules that should be loaded as plugins: PYTEST_DISABLE_PLUGIN_AUTOLOAD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When set, disables plugin auto-loading through setuptools entrypoints. Only explicitly specified plugins will be -loaded. +Set to "1" to disable plugin auto-loading through setuptools entrypoints. +Only explicitly specified plugins will be loaded then. PYTEST_CURRENT_TEST ~~~~~~~~~~~~~~~~~~~ diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 1897f523be2..126d148488d 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -757,7 +757,7 @@ def _mark_plugins_for_rewrite(self, hook): self.pluginmanager.rewrite_hook = hook - if os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"): + if bool(int(os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "0"))): # We don't autoload from setuptools entry points, no need to continue. return @@ -786,7 +786,7 @@ def _preparse(self, args, addopts=True): self._checkversion() self._consider_importhook(args) self.pluginmanager.consider_preparse(args) - if not os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"): + if not bool(int(os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "0"))): # Don't autoload from setuptools entry point. Only explicitly specified # plugins are going to be loaded. self.pluginmanager.load_setuptools_entrypoints("pytest11") diff --git a/src/_pytest/helpconfig.py b/src/_pytest/helpconfig.py index 5e60d2a7f94..2a222d9d2b5 100644 --- a/src/_pytest/helpconfig.py +++ b/src/_pytest/helpconfig.py @@ -160,7 +160,7 @@ def showhelp(config): vars = [ ("PYTEST_ADDOPTS", "extra command line options"), ("PYTEST_PLUGINS", "comma-separated plugins to load during startup"), - ("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "set to disable plugin auto-loading"), + ("PYTEST_DISABLE_PLUGIN_AUTOLOAD", 'set to "1" to disable plugin auto-loading'), ("PYTEST_DEBUG", "set to enable debug tracing of pytest's internals"), ] for name, help in vars: diff --git a/testing/test_config.py b/testing/test_config.py index fcb886d5317..291947c1a25 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -612,18 +612,36 @@ def load(self): @pytest.mark.parametrize( - "parse_args,should_load", [(("-p", "mytestplugin"), True), ((), False)] + "env,parse_args,should_load", + [("1", ("-p", "mytestplugin"), True), ("1", (), False), ("0", (), True)], ) -def test_disable_plugin_autoload(testdir, monkeypatch, parse_args, should_load): +def test_disable_plugin_autoload(testdir, monkeypatch, env, parse_args, should_load): pkg_resources = pytest.importorskip("pkg_resources") - def my_iter(name): - raise AssertionError("Should not be called") - class PseudoPlugin(object): x = 42 - monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1") + def my_iter(name): + if env == "1": + raise AssertionError("Should not be called") + + class Dist(object): + project_name = "spam" + version = "1.0" + + def _get_metadata(self, name): + return ["foo.txt,sha256=abc,123"] + + class EntryPoint(object): + name = "mytestplugin" + dist = Dist() + + def load(self): + return PseudoPlugin() + + return iter([EntryPoint()]) + + monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", env) monkeypatch.setattr(pkg_resources, "iter_entry_points", my_iter) monkeypatch.setitem(sys.modules, "mytestplugin", PseudoPlugin()) config = testdir.parseconfig(*parse_args)