MCPcopy
hub / github.com/pytest-dev/pytest / pytest_pycollect_makeitem

Function pytest_pycollect_makeitem

src/_pytest/python.py:220–252  ·  view source on GitHub ↗
(
    collector: Module | Class, name: str, obj: object
)

Source from the content-addressed store, hash-verified

218
219@hookimpl(trylast=True)
220def pytest_pycollect_makeitem(
221 collector: Module | Class, name: str, obj: object
222) -> None | nodes.Item | nodes.Collector | list[nodes.Item | nodes.Collector]:
223 assert isinstance(collector, Class | Module), type(collector)
224 # Nothing was collected elsewhere, let's do it here.
225 if safe_isclass(obj):
226 if collector.istestclass(obj, name):
227 return Class.from_parent(collector, name=name, obj=obj)
228 elif collector.istestfunction(obj, name):
229 # mock seems to store unbound methods (issue473), normalize it.
230 obj = getattr(obj, "__func__", obj)
231 # We need to try and unwrap the function if it's a functools.partial
232 # or a functools.wrapped.
233 # We mustn't if it's been wrapped with mock.patch (python 2 only).
234 if not (inspect.isfunction(obj) or inspect.isfunction(get_real_func(obj))):
235 filename, lineno = getfslineno(obj)
236 warnings.warn_explicit(
237 message=PytestCollectionWarning(
238 f"cannot collect {name!r} because it is not a function."
239 ),
240 category=None,
241 filename=str(filename),
242 lineno=lineno + 1,
243 )
244 elif getattr(obj, "__test__", True):
245 if inspect.isgeneratorfunction(obj):
246 fail(
247 f"'yield' keyword is allowed in fixtures, but not in tests ({name})",
248 pytrace=False,
249 )
250 return list(collector._genfunctions(name, obj))
251 return None
252 return None
253
254
255class PyobjMixin(nodes.Node):

Callers

nothing calls this directly

Calls 8

safe_isclassFunction · 0.90
get_real_funcFunction · 0.90
getfslinenoFunction · 0.90
istestclassMethod · 0.80
istestfunctionMethod · 0.80
_genfunctionsMethod · 0.80
from_parentMethod · 0.45

Tested by

no test coverage detected