diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index d9ca76d05..3f7c06749 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -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