diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index 15214676..d05b49fe 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -197,6 +197,12 @@ def register(self, plugin: _Plugin, name: str | None = None) -> str | None: # Registering a `None` plugin causes problems (#731). However, some # users are doing it, so can't error out (#749). Just ignore # instead. + warnings.warn( + "Passing None to PluginManager.register() is deprecated and will be " + "removed in a future release.", + DeprecationWarning, + stacklevel=2, + ) return None plugin_name = name or self.get_canonical_name(plugin) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index be34efb1..de1a1a3b 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -31,7 +31,11 @@ def test_plugin_double_register(pm: PluginManager) -> None: def test_register_ignores_none(pm: PluginManager) -> None: """``None`` collides with the blocked-name sentinel and must be ignored.""" - assert pm.register(None) is None + with pytest.warns( + DeprecationWarning, + match=r"Passing None to PluginManager\.register\(\) is deprecated", + ): + assert pm.register(None) is None assert pm.get_plugins() == set() assert not pm.is_registered(None) @@ -1029,7 +1033,11 @@ def register(self, plugin: object, name: str | None = None) -> str | None: monkeypatch.setattr(importlib.metadata, "distributions", lambda: (dist,)) pm = DecliningPluginManager("example") - assert pm.load_setuptools_entrypoints("hello") == 1 + with pytest.warns( + DeprecationWarning, + match=r"Passing None to PluginManager\.register\(\) is deprecated", + ): + assert pm.load_setuptools_entrypoints("hello") == 1 assert pm.list_plugin_distributions() == [(accepted, dist)]