(
collector: Module | Class, name: str, obj: object
)
| 218 | |
| 219 | @hookimpl(trylast=True) |
| 220 | def 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 | |
| 255 | class PyobjMixin(nodes.Node): |
nothing calls this directly
no test coverage detected