fix hookspec parsing

This commit is contained in:
Ronny Pfannschmidt 2018-12-19 20:41:13 +01:00
parent 9f9f6ee48b
commit 3947b859dc
1 changed files with 8 additions and 3 deletions

View File

@ -268,10 +268,10 @@ class PytestPluginManager(PluginManager):
# collect unmarked hooks as long as they have the `pytest_' prefix
if opts is None and name.startswith("pytest_"):
opts = {}
if opts is not None:
# TODO: DeprecationWarning, people should use hookimpl
known_marks = {m.name for m in getattr(method, "pytestmark", [])}
for name in ("tryfirst", "trylast", "optionalhook", "hookwrapper"):
opts.setdefault(name, hasattr(method, name) or name in known_marks)
@ -283,10 +283,15 @@ class PytestPluginManager(PluginManager):
)
if opts is None:
method = getattr(module_or_class, name)
if name.startswith("pytest_"):
# todo: deprecate hookspec hacks
known_marks = {m.name for m in getattr(method, "pytestmark", [])}
opts = {
"firstresult": hasattr(method, "firstresult"),
"historic": hasattr(method, "historic"),
"firstresult": hasattr(method, "firstresult")
or "firstresult" in known_marks,
"historic": hasattr(method, "historic")
or "historic" in known_marks,
}
return opts