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

Method collect

src/_pytest/python.py:757–786  ·  src/_pytest/python.py::Class.collect
(self)

Source from the content-addressed store, hash-verified

755 return self.obj()
756
757 def collect(self) -> Iterable[nodes.Item | nodes.Collector]:
758 if not safe_getattr(self.obj, class="st">"__test__", True):
759 return []
760 if hasinit(self.obj):
761 assert self.parent is not None
762 self.warn(
763 PytestCollectionWarning(
764 fclass="st">"cannot collect test class {self.obj.__name__!r} because it has a "
765 fclass="st">"__init__ constructor (from: {self.parent.nodeid})"
766 )
767 )
768 return []
769 elif hasnew(self.obj):
770 assert self.parent is not None
771 self.warn(
772 PytestCollectionWarning(
773 fclass="st">"cannot collect test class {self.obj.__name__!r} because it has a "
774 fclass="st">"__new__ constructor (from: {self.parent.nodeid})"
775 )
776 )
777 return []
778
779 self._register_setup_class_fixture()
780 self._register_setup_method_fixture()
781
782 self.session._fixturemanager.parsefactories(
783 holder=self.newinstance(), node=self
784 )
785
786 return super().collect()
787
788 def _register_setup_class_fixture(self) -> None:
789 class="st">"""Register an autouse, class scoped fixture into the collected class object

Callers 1

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

no test coverage detected