MCPcopy Create free account
hub / github.com/pytest-dev/pytest / pytest_pycollect_makeitem

Function pytest_pycollect_makeitem

src/_pytest/python.py:227–258  ·  view source on GitHub ↗
(collector: "PyCollector", name: str, obj: object)

Source from the content-addressed store, hash-verified

225
226@hookimpl(trylast=True)
227def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object):
228 # Nothing was collected elsewhere, let's do it here.
229 if safe_isclass(obj):
230 if collector.istestclass(obj, name):
231 return Class.from_parent(collector, name=name, obj=obj)
232 elif collector.istestfunction(obj, name):
233 # mock seems to store unbound methods (issue473), normalize it.
234 obj = getattr(obj, "__func__", obj)
235 # We need to try and unwrap the function if it's a functools.partial
236 # or a functools.wrapped.
237 # We mustn't if it's been wrapped with mock.patch (python 2 only).
238 if not (inspect.isfunction(obj) or inspect.isfunction(get_real_func(obj))):
239 filename, lineno = getfslineno(obj)
240 warnings.warn_explicit(
241 message=PytestCollectionWarning(
242 "cannot collect %r because it is not a function." % name
243 ),
244 category=None,
245 filename=str(filename),
246 lineno=lineno + 1,
247 )
248 elif getattr(obj, "__test__", True):
249 if is_generator(obj):
250 res = Function.from_parent(collector, name=name)
251 reason = "yield tests were removed in pytest 4.0 - {name} will be ignored".format(
252 name=name
253 )
254 res.add_marker(MARK_GEN.xfail(run=False, reason=reason))
255 res.warn(PytestCollectionWarning(reason))
256 else:
257 res = list(collector._genfunctions(name, obj))
258 return res
259
260
261class PyobjMixin(nodes.Node):

Callers

nothing calls this directly

Calls 12

safe_isclassFunction · 0.90
get_real_funcFunction · 0.90
getfslinenoFunction · 0.90
is_generatorFunction · 0.90
istestclassMethod · 0.80
istestfunctionMethod · 0.80
add_markerMethod · 0.80
_genfunctionsMethod · 0.80
from_parentMethod · 0.45
formatMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected