Skip to content

Remove stale plugin distribution entries on unregister - #789

Closed
antiren1980-ship-it wants to merge 1 commit into
pytest-dev:mainfrom
antiren1980-ship-it:fix/unregister-plugin-distinfo
Closed

antiren1980-ship-it wants to merge 1 commit into
pytest-dev:mainfrom
antiren1980-ship-it:fix/unregister-plugin-distinfo

Conversation

@antiren1980-ship-it

Copy link
Copy Markdown

Summary

load_setuptools_entrypoints() appends to _plugin_distinfo, but unregister() only removed the plugin from _name2plugin and its hook callers. As a result:

  • list_plugin_distinfo() and list_plugin_distributions() kept reporting an unregistered plugin;
  • re-registering the plugin added a duplicate entry.

unregister() now also drops the plugin's _plugin_distinfo entries, so both views stay in sync and re-registration does not create duplicates.

Fix

src/pluggy/_manager.py — after removing the plugin from _name2plugin, filter it out of _plugin_distinfo:

self._plugin_distinfo[:] = [
    (p, dist) for (p, dist) in self._plugin_distinfo if p is not plugin
]

Tests

Added test_unregister_removes_plugin_distinfo which:

  1. loads a plugin via load_setuptools_entrypoints(),
  2. unregisters it and asserts both list_plugin_distinfo() and list_plugin_distributions() are empty,
  3. re-registers it and asserts there is exactly one entry (no duplicate).

The test fails on main and passes with the fix.

78 passed

Fixes #763

'load_setuptools_entrypoints()' appends to '_plugin_distinfo', but
'unregister()' only removed the plugin from '_name2plugin' and the hook
callers. As a result 'list_plugin_distinfo()' and
'list_plugin_distributions()' kept reporting an unregistered plugin, and
re-registering it added a duplicate entry.

'unregister()' now also drops the plugin's '_plugin_distinfo' entries.

Fixes pytest-dev#763
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list_plugin_distinfo() keeps unregistered plugins

2 participants