Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/en/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 24 additions & 6 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down