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

Method _genfunctions

src/_pytest/python.py:455–503  ·  view source on GitHub ↗
(self, name: str, funcobj)

Source from the content-addressed store, hash-verified

453 return result
454
455 def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
456 modulecol = self.getparent(Module)
457 assert modulecol is not None
458 module = modulecol.obj
459 clscol = self.getparent(Class)
460 cls = clscol and clscol.obj or None
461
462 definition = FunctionDefinition.from_parent(self, name=name, callobj=funcobj)
463 fixtureinfo = definition._fixtureinfo
464
465 # pytest_generate_tests impls call metafunc.parametrize() which fills
466 # metafunc._calls, the outcome of the hook.
467 metafunc = Metafunc(
468 definition=definition,
469 fixtureinfo=fixtureinfo,
470 config=self.config,
471 cls=cls,
472 module=module,
473 _ispytest=True,
474 )
475 methods = []
476 if hasattr(module, "pytest_generate_tests"):
477 methods.append(module.pytest_generate_tests)
478 if cls is not None and hasattr(cls, "pytest_generate_tests"):
479 methods.append(cls().pytest_generate_tests)
480 self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
481
482 if not metafunc._calls:
483 yield Function.from_parent(self, name=name, fixtureinfo=fixtureinfo)
484 else:
485 # Add funcargs() as fixturedefs to fixtureinfo.arg2fixturedefs.
486 fm = self.session._fixturemanager
487 fixtures.add_funcarg_pseudo_fixture_def(self, metafunc, fm)
488
489 # Add_funcarg_pseudo_fixture_def may have shadowed some fixtures
490 # with direct parametrization, so make sure we update what the
491 # function really needs.
492 fixtureinfo.prune_dependency_tree()
493
494 for callspec in metafunc._calls:
495 subname = f"{name}[{callspec.id}]"
496 yield Function.from_parent(
497 self,
498 name=subname,
499 callspec=callspec,
500 fixtureinfo=fixtureinfo,
501 keywords={callspec.id: True},
502 originalname=name,
503 )
504
505
506class Module(nodes.File, PyCollector):

Callers 1

Calls 6

MetafuncClass · 0.85
clsFunction · 0.85
getparentMethod · 0.80
appendMethod · 0.80
prune_dependency_treeMethod · 0.80
from_parentMethod · 0.45

Tested by

no test coverage detected