diff --git a/_pytest/config.py b/_pytest/config.py index 8be167a21..0495aa21f 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -159,6 +159,7 @@ class PytestPluginManager(PluginManager): """ warning = dict(code="I2", fslocation=py.code.getfslineno(sys._getframe(1)), + nodeid=None, message="use pluginmanager.add_hookspecs instead of " "deprecated addhooks() method.") self._warn(warning) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index c49938100..97daf2eae 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -145,6 +145,23 @@ class TestPytestPluginInteractions: assert len(warnings) == len(before) + 1 assert "deprecated" in warnings[-1] + def test_warn_on_deprecated_addhooks(self, pytestpm): + warnings = [] + + class get_warnings: + def pytest_logwarning(self, code, fslocation, message, nodeid): + warnings.append(message) + + class Plugin: + def pytest_testhook(): + pass + + pytestpm.register(get_warnings()) + before = list(warnings) + pytestpm.addhooks(Plugin()) + assert len(warnings) == len(before) + 1 + assert "deprecated" in warnings[-1] + def test_namespace_has_default_and_env_plugins(testdir): p = testdir.makepyfile("""