Skip to content

Commit 2fb21c8

Browse files
committed
Fix error when handling VersionConflict exceptions from setuptools entry points
1 parent 2c4ecb0 commit 2fb21c8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

changelog/160.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix problem when handling ``VersionConflict`` errors when loading setuptools plugins.

pluggy/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def load_setuptools_entrypoints(self, entrypoint_name):
255255
continue
256256
except VersionConflict as e:
257257
raise PluginValidationError(
258-
"Plugin %r could not be loaded: %s!" % (ep.name, e))
258+
plugin=None,
259+
message="Plugin %r could not be loaded: %s!" % (ep.name, e))
259260
self.register(plugin, name=ep.name)
260261
self._plugin_distinfo.append((plugin, ep.dist))
261262
return len(self._plugin_distinfo)

testing/test_pluginmanager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,28 @@ class PseudoPlugin(object):
427427
assert pm.list_plugin_distinfo() == [(plugin, None)]
428428

429429

430+
def test_load_setuptools_version_conflict(monkeypatch, pm):
431+
"""Check that we properly handle a VersionConflict problem when loading entry points"""
432+
pkg_resources = pytest.importorskip("pkg_resources")
433+
434+
def my_iter(name):
435+
assert name == "hello"
436+
437+
class EntryPoint(object):
438+
name = "myname"
439+
dist = None
440+
441+
def load(self):
442+
raise pkg_resources.VersionConflict('Some conflict')
443+
444+
return iter([EntryPoint()])
445+
446+
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
447+
with pytest.raises(PluginValidationError,
448+
match="Plugin 'myname' could not be loaded: Some conflict!"):
449+
pm.load_setuptools_entrypoints("hello")
450+
451+
430452
def test_load_setuptools_not_installed(monkeypatch, pm):
431453
monkeypatch.setitem(
432454
sys.modules, 'pkg_resources',

0 commit comments

Comments
 (0)