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

Method collect

src/_pytest/python.py:793–822  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

791 return self.obj()
792
793 def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
794 if not safe_getattr(self.obj, "__test__", True):
795 return []
796 if hasinit(self.obj):
797 assert self.parent is not None
798 self.warn(
799 PytestCollectionWarning(
800 "cannot collect test class %r because it has a "
801 "__init__ constructor (from: %s)"
802 % (self.obj.__name__, self.parent.nodeid)
803 )
804 )
805 return []
806 elif hasnew(self.obj):
807 assert self.parent is not None
808 self.warn(
809 PytestCollectionWarning(
810 "cannot collect test class %r because it has a "
811 "__new__ constructor (from: %s)"
812 % (self.obj.__name__, self.parent.nodeid)
813 )
814 )
815 return []
816
817 self._inject_setup_class_fixture()
818 self._inject_setup_method_fixture()
819
820 self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
821
822 return super().collect()
823
824 def _inject_setup_class_fixture(self) -> None:
825 """Inject a hidden autouse, class scoped fixture into the collected class object

Callers 4

collect_by_nameMethod · 0.45
collectMethod · 0.45

Calls 9

newinstanceMethod · 0.95
safe_getattrFunction · 0.90
hasinitFunction · 0.85
hasnewFunction · 0.85
parsefactoriesMethod · 0.80
warnMethod · 0.45

Tested by 2

collect_by_nameMethod · 0.36