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:
parent
e492b1d567
commit
40c355f8c3
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue