Skip to content

list_plugin_distributions() raises KeyError for entry points that register() declined (regression from #767)聽#807

Closed

Description

@RonnyPfannschmidt

馃 Written by Claude Opus 5.5 via Claude Code for the pluggy maintainers; I prompted it, it did the work, I read it.

Since #767 (merged, unreleased), load_setuptools_entrypoints() records every loaded entry point in _name2dist keyed by ep.name, whether or not register() actually registered it:

plugin = ep.load()
self.register(plugin, name=ep.name)
self._name2dist[ep.name] = dist
count += 1

list_plugin_distributions() then looks each name up with self._name2plugin[name], and list_plugin_distinfo() calls it. When register() declines a plugin (it returns None for a None plugin, and pytest's PytestPluginManager.register() returns None for the plugins merged into pytest such as pytest_faulthandler and pytest_catchlog), the name is recorded but never registered. The lookup then fails with KeyError.

Impact: with pytest-faulthandler installed, a pytest run built on pluggy main crashes with INTERNALERROR ... KeyError: 'pytest_faulthandler' while printing the header, because the header lists plugins through list_plugin_distinfo(). 1.7.0 is not affected because it stored (plugin, dist) pairs.

Fix: use the return value of register(). Skip the bookkeeping and the count when it is None, and otherwise key _name2dist by the returned name. The test should cover a None plugin and a PluginManager subclass whose register() returns None.

Found while reviewing #804.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions