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.
This commit is contained in:
Ran Benita 2020-06-29 23:31:01 +03:00
parent e492b1d567
commit 40c355f8c3
1 changed files with 4 additions and 8 deletions

View File

@ -209,16 +209,12 @@ def pytest_pycollect_makemodule(path: py.path.local, parent) -> "Module":
return mod return mod
@hookimpl(hookwrapper=True) @hookimpl(trylast=True)
def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj): def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object):
outcome = yield
res = outcome.get_result()
if res is not None:
return
# nothing was collected elsewhere, let's do it here # nothing was collected elsewhere, let's do it here
if safe_isclass(obj): if safe_isclass(obj):
if collector.istestclass(obj, name): 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): elif collector.istestfunction(obj, name):
# mock seems to store unbound methods (issue473), normalize it # mock seems to store unbound methods (issue473), normalize it
obj = getattr(obj, "__func__", obj) obj = getattr(obj, "__func__", obj)
@ -245,7 +241,7 @@ def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj):
res.warn(PytestCollectionWarning(reason)) res.warn(PytestCollectionWarning(reason))
else: else:
res = list(collector._genfunctions(name, obj)) res = list(collector._genfunctions(name, obj))
outcome.force_result(res) return res
class PyobjMixin: class PyobjMixin: