Skip to content

Commit 757f37f

Browse files
committed
Don't ignore ImportError with setuptools plugins
This was added in b2d66b9 but is a bad idea. When a plugin can't be imported, commandline options (optionally set in pytest.ini) could be undefined, which means pytest bails out much earlier before showing the warning, which is hard to debug. Fixes #1479, also see #1307 and #1497
1 parent 0c63762 commit 757f37f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

_pytest/config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,7 @@ def _preparse(self, args, addopts=True):
923923
args[:] = self.getini("addopts") + args
924924
self._checkversion()
925925
self.pluginmanager.consider_preparse(args)
926-
try:
927-
self.pluginmanager.load_setuptools_entrypoints("pytest11")
928-
except ImportError as e:
929-
self.warn("I2", "could not load setuptools entry import: %s" % (e,))
926+
self.pluginmanager.load_setuptools_entrypoints("pytest11")
930927
self.pluginmanager.consider_env()
931928
self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy())
932929
if self.known_args_namespace.confcutdir is None and self.inifile:

testing/test_config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ class PseudoPlugin:
391391
plugin = config.pluginmanager.getplugin("mytestplugin")
392392
assert plugin.x == 42
393393

394+
395+
def test_setuptools_importerror_issue1479(testdir, monkeypatch):
396+
pkg_resources = pytest.importorskip("pkg_resources")
397+
def my_iter(name):
398+
assert name == "pytest11"
399+
class EntryPoint:
400+
name = "mytestplugin"
401+
dist = None
402+
def load(self):
403+
raise ImportError("Don't hide me!")
404+
return iter([EntryPoint()])
405+
406+
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
407+
with pytest.raises(ImportError):
408+
testdir.parseconfig()
409+
410+
394411
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
395412
pkg_resources = pytest.importorskip("pkg_resources")
396413
def my_iter(name):

0 commit comments

Comments
 (0)