From b3727438d6f39cf63f1ace443d56e7f0362b1da3 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 28 Sep 2015 12:05:58 -0400 Subject: [PATCH] Add missing nodeid on pytest_logwarning call in addhook. Otherwise KeyError: 'nodeid' gets thrown, killing pytest. This may fix issue 1034, but the details of it may be caused by something similar somewhere else. --- _pytest/config.py | 1 + testing/test_pluginmanager.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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("""