Skip to content

fix(manager): drop the distinfo entry when a plugin is unregistered - #797

Closed
ciperx wants to merge 2 commits into
pytest-dev:mainfrom
ciperx:fix/unregister-distinfo-763
Closed

ciperx wants to merge 2 commits into
pytest-dev:mainfrom
ciperx:fix/unregister-distinfo-763

Conversation

@ciperx

@ciperx ciperx commented Oct 16, 2026

Copy link
Copy Markdown

Fixes #763.

PluginManager.unregister() removed the plugin from its hook callers and from _name2plugin, but left its _plugin_distinfo entry in place. For a plugin loaded through entry points that means:

  • list_plugin_distinfo() and list_plugin_distributions() kept reporting the plugin after it had been unregistered, so the listings disagreed with get_plugin() / has_plugin().
  • Re-registering the plugin appended a second entry for the same plugin, so the listings grew on every unregister/reload cycle.

Change

unregister() now also removes the distinfo entries belonging to that plugin:

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

Rebinding in place (rather than assigning a new list) keeps the existing list object, since the attribute is annotated Final. No public API change, no new dependency.

Regression coverage

testing/test_unregister_distinfo.py covers three paths:

  • unregistering by name removes the plugin from both list_plugin_distinfo() and list_plugin_distributions();
  • unregister then register does not leave a stale entry, and a later entry-point reload produces exactly one entry again;
  • unregistering by plugin object clears the bookkeeping as well.

Verification

$ python -m pytest testing/ -q
222 passed

With the _plugin_distinfo cleanup reverted, all three new tests fail (3 failed), so the coverage is not vacuous.


This work was completed for OpenJobs listing eb2edb80-4a8f-4a90-9d26-859c4b977f65 (https://openjobs.bot/jobs/eb2edb80-4a8f-4a90-9d26-859c4b977f65).

ciperx and others added 2 commits October 16, 2026 15:44
PluginManager.unregister removed the plugin from its hook callers and from
_name2plugin, but left its _plugin_distinfo entry behind. A plugin loaded through
entry points therefore kept being reported by list_plugin_distinfo() and
list_plugin_distributions() after unregister(), and re-registering it appended a
second entry for the same plugin.

unregister now removes every distinfo entry belonging to the plugin, so both
listings reflect the live registry. Adds regression coverage for the name form,
the plugin-object form, and the unregister-then-reload path.
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