@@ -224,11 +224,15 @@ def pytest_pycollect_makemodule(module_path: Path, parent) -> "Module":
224224
225225
226226@hookimpl (trylast = True )
227- def pytest_pycollect_makeitem (collector : "PyCollector" , name : str , obj : object ):
227+ def pytest_pycollect_makeitem (
228+ collector : Union ["Module" , "Class" ], name : str , obj : object
229+ ) -> Union [None , nodes .Item , nodes .Collector , List [Union [nodes .Item , nodes .Collector ]]]:
230+ assert isinstance (collector , (Class , Module )), type (collector )
228231 # Nothing was collected elsewhere, let's do it here.
229232 if safe_isclass (obj ):
230233 if collector .istestclass (obj , name ):
231- return Class .from_parent (collector , name = name , obj = obj )
234+ klass : Class = Class .from_parent (collector , name = name , obj = obj )
235+ return klass
232236 elif collector .istestfunction (obj , name ):
233237 # mock seems to store unbound methods (issue473), normalize it.
234238 obj = getattr (obj , "__func__" , obj )
@@ -247,15 +251,16 @@ def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object):
247251 )
248252 elif getattr (obj , "__test__" , True ):
249253 if is_generator (obj ):
250- res = Function .from_parent (collector , name = name )
254+ res : Function = Function .from_parent (collector , name = name )
251255 reason = "yield tests were removed in pytest 4.0 - {name} will be ignored" .format (
252256 name = name
253257 )
254258 res .add_marker (MARK_GEN .xfail (run = False , reason = reason ))
255259 res .warn (PytestCollectionWarning (reason ))
260+ return res
256261 else :
257- res = list (collector ._genfunctions (name , obj ))
258- return res
262+ return list (collector ._genfunctions (name , obj ))
263+ return None
259264
260265
261266class PyobjMixin (nodes .Node ):
0 commit comments