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.
This commit is contained in:
Simon Gomizelj 2015-09-28 12:05:58 -04:00 committed by Simon Gomizelj
parent 22e1f4946e
commit b3727438d6
2 changed files with 18 additions and 0 deletions

View File

@ -159,6 +159,7 @@ class PytestPluginManager(PluginManager):
""" """
warning = dict(code="I2", warning = dict(code="I2",
fslocation=py.code.getfslineno(sys._getframe(1)), fslocation=py.code.getfslineno(sys._getframe(1)),
nodeid=None,
message="use pluginmanager.add_hookspecs instead of " message="use pluginmanager.add_hookspecs instead of "
"deprecated addhooks() method.") "deprecated addhooks() method.")
self._warn(warning) self._warn(warning)

View File

@ -145,6 +145,23 @@ class TestPytestPluginInteractions:
assert len(warnings) == len(before) + 1 assert len(warnings) == len(before) + 1
assert "deprecated" in warnings[-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): def test_namespace_has_default_and_env_plugins(testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""