From 40c355f8c3554a2002976d9f5426ca53293ccf59 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 29 Jun 2020 23:31:01 +0300 Subject: [PATCH] python: pytest_pycollect_makeitem doesn't need to be a hookwrapper A trylast is more appropriate for this usecase. hookwrappers are more complicated and more expensive than regular hookimpls, so better avoided. --- src/_pytest/python.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 65855ca23..c5cd14bdc 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -209,16 +209,12 @@ def pytest_pycollect_makemodule(path: py.path.local, parent) -> "Module": return mod -@hookimpl(hookwrapper=True) -def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj): - outcome = yield - res = outcome.get_result() - if res is not None: - return +@hookimpl(trylast=True) +def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object): # nothing was collected elsewhere, let's do it here if safe_isclass(obj): if collector.istestclass(obj, name): - outcome.force_result(Class.from_parent(collector, name=name, obj=obj)) + return Class.from_parent(collector, name=name, obj=obj) elif collector.istestfunction(obj, name): # mock seems to store unbound methods (issue473), normalize it obj = getattr(obj, "__func__", obj) @@ -245,7 +241,7 @@ def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj): res.warn(PytestCollectionWarning(reason)) else: res = list(collector._genfunctions(name, obj)) - outcome.force_result(res) + return res class PyobjMixin: