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

Method collect

src/_pytest/unittest.py:65–94  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

63 nofuncargs = True
64
65 def collect(self) -> Iterable[Union[Item, Collector]]:
66 from unittest import TestLoader
67
68 cls = self.obj
69 if not getattr(cls, "__test__", True):
70 return
71
72 skipped = _is_skipped(cls)
73 if not skipped:
74 self._inject_setup_teardown_fixtures(cls)
75 self._inject_setup_class_fixture()
76
77 self.session._fixturemanager.parsefactories(self, unittest=True)
78 loader = TestLoader()
79 foundsomething = False
80 for name in loader.getTestCaseNames(self.obj):
81 x = getattr(self.obj, name)
82 if not getattr(x, "__test__", True):
83 continue
84 funcobj = getimfunc(x)
85 yield TestCaseFunction.from_parent(self, name=name, callobj=funcobj)
86 foundsomething = True
87
88 if not foundsomething:
89 runtest = getattr(self.obj, "runTest", None)
90 if runtest is not None:
91 ut = sys.modules.get("twisted.trial.unittest", None)
92 # Type ignored because `ut` is an opaque module.
93 if ut is None or runtest != ut.TestCase.runTest: # type: ignore
94 yield TestCaseFunction.from_parent(self, name="runTest")
95
96 def _inject_setup_teardown_fixtures(self, cls: type) -> None:
97 """Injects a hidden auto-use fixture to invoke setUpClass/setup_method and corresponding

Callers

nothing calls this directly

Calls 7

getimfuncFunction · 0.90
_is_skippedFunction · 0.85
parsefactoriesMethod · 0.80
from_parentMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected