Skip to content

Don't ignore ImportError when importing setuptools plugins #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2016
Merged
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
5 changes: 1 addition & 4 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,7 @@ def _preparse(self, args, addopts=True):
args[:] = self.getini("addopts") + args
self._checkversion()
self.pluginmanager.consider_preparse(args)
try:
self.pluginmanager.load_setuptools_entrypoints("pytest11")
except ImportError as e:
self.warn("I2", "could not load setuptools entry import: %s" % (e,))
self.pluginmanager.load_setuptools_entrypoints("pytest11")
self.pluginmanager.consider_env()
self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy())
if self.known_args_namespace.confcutdir is None and self.inifile:
Expand Down
17 changes: 17 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,23 @@ class PseudoPlugin:
plugin = config.pluginmanager.getplugin("mytestplugin")
assert plugin.x == 42


def test_setuptools_importerror_issue1479(testdir, monkeypatch):
pkg_resources = pytest.importorskip("pkg_resources")
def my_iter(name):
assert name == "pytest11"
class EntryPoint:
name = "mytestplugin"
dist = None
def load(self):
raise ImportError("Don't hide me!")
return iter([EntryPoint()])

monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
with pytest.raises(ImportError):
testdir.parseconfig()


def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
pkg_resources = pytest.importorskip("pkg_resources")
def my_iter(name):
Expand Down