@@ -224,11 +224,15 @@ def pytest_pycollect_makemodule(module_path: Path, parent) -> "Module":
224
224
225
225
226
226
@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 )
228
231
# Nothing was collected elsewhere, let's do it here.
229
232
if safe_isclass (obj ):
230
233
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
232
236
elif collector .istestfunction (obj , name ):
233
237
# mock seems to store unbound methods (issue473), normalize it.
234
238
obj = getattr (obj , "__func__" , obj )
@@ -247,15 +251,16 @@ def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object):
247
251
)
248
252
elif getattr (obj , "__test__" , True ):
249
253
if is_generator (obj ):
250
- res = Function .from_parent (collector , name = name )
254
+ res : Function = Function .from_parent (collector , name = name )
251
255
reason = "yield tests were removed in pytest 4.0 - {name} will be ignored" .format (
252
256
name = name
253
257
)
254
258
res .add_marker (MARK_GEN .xfail (run = False , reason = reason ))
255
259
res .warn (PytestCollectionWarning (reason ))
260
+ return res
256
261
else :
257
- res = list (collector ._genfunctions (name , obj ))
258
- return res
262
+ return list (collector ._genfunctions (name , obj ))
263
+ return None
259
264
260
265
261
266
class PyobjMixin (nodes .Node ):
0 commit comments