Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PluginManager.unblock method to unblock a name #471

Merged
merged 1 commit into from
Jan 24, 2024
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
10 changes: 10 additions & 0 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@
"""Return whether the given plugin name is blocked."""
return name in self._name2plugin and self._name2plugin[name] is None

def unblock(self, name: str) -> bool:
"""Unblocks a name.

Check warning on line 240 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L240

Added line #L240 was not covered by tests
Returns whether the name was actually blocked.
"""

Check warning on line 242 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L242

Added line #L242 was not covered by tests
if self._name2plugin.get(name, -1) is None:
del self._name2plugin[name]
return True
return False

Check warning on line 247 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L247

Added line #L247 was not covered by tests
def add_hookspecs(self, module_or_class: _Namespace) -> None:
"""Add new hook specifications defined in the given ``module_or_class``.

Expand Down
7 changes: 7 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class A:
pm.unregister(name="somename")
assert pm.is_blocked("somename")

# Unblock.
assert not pm.unblock("someothername")
assert pm.unblock("somename")
assert not pm.is_blocked("somename")
assert not pm.unblock("somename")
assert pm.register(A(), "somename")


def test_register_mismatch_method(he_pm: PluginManager) -> None:
class hello:
Expand Down