Skip to content
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
1 change: 1 addition & 0 deletions changelog/807.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :meth:`~pluggy.PluginManager.load_setuptools_entrypoints` crashing distribution listing when an entry point is declined during registration.
6 changes: 4 additions & 2 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,10 @@ def load_setuptools_entrypoints(self, group: str, name: str | None = None) -> in
):
continue
plugin = ep.load()
self.register(plugin, name=ep.name)
self._name2dist[ep.name] = dist
plugin_name = self.register(plugin, name=ep.name)
if plugin_name is None:
continue
self._name2dist[plugin_name] = dist
count += 1
return count

Expand Down
38 changes: 38 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,44 @@ class Distribution:
assert pm.list_plugin_distributions() == [(a, dist)]


def test_load_setuptools_ignores_declined_plugins(
monkeypatch: pytest.MonkeyPatch,
) -> None:
class EntryPoint:
group = "hello"

def __init__(self, name: str, plugin: object) -> None:
self.name = name
self.plugin = plugin

def load(self) -> object:
return self.plugin

accepted = object()

class Distribution:
entry_points = (
EntryPoint("none-plugin", None),
EntryPoint("declined", object()),
EntryPoint("renamed", accepted),
)

class DecliningPluginManager(PluginManager):
def register(self, plugin: object, name: str | None = None) -> str | None:
if name == "declined":
return None
if name == "renamed":
name = "accepted"
return super().register(plugin, name)

dist = cast(importlib.metadata.Distribution, Distribution())
monkeypatch.setattr(importlib.metadata, "distributions", lambda: (dist,))
pm = DecliningPluginManager("example")

assert pm.load_setuptools_entrypoints("hello") == 1
assert pm.list_plugin_distributions() == [(accepted, dist)]


def test_add_tracefuncs(he_pm: PluginManager) -> None:
out: list[Any] = []

Expand Down
Loading