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

Method getitem

src/_pytest/pytester.py:1268–1288  ·  src/_pytest/pytester.py::Pytester.getitem

Return the test item for a test function. Writes the source to a python file and runs pytest's collection on the resulting module, returning the test item for the requested function name. :param source: The module source. :param funcname:

(
        self, source: str | os.PathLike[str], funcname: str = "test_func"
    )

Source from the content-addressed store, hash-verified

1266 return config
1267
1268 def getitem(
1269 self, source: str | os.PathLike[str], funcname: str = class="st">"test_func"
1270 ) -> Item:
1271 class="st">"""Return the test item for a test function.
1272
1273 Writes the source to a python file and runs pytest&class="cm">#x27;s collection on
1274 the resulting module, returning the test item for the requested
1275 function name.
1276
1277 :param source:
1278 The module source.
1279 :param funcname:
1280 The name of the test function for which to return a test item.
1281 :returns:
1282 The test item.
1283 class="st">"""
1284 items = self.getitems(source)
1285 for item in items:
1286 if item.name == funcname:
1287 return item
1288 assert 0, fclass="st">"{funcname!r} item not found in module:\n{source}\nitems: {items}"
1289
1290 def getitems(self, source: str | os.PathLike[str]) -> list[Item]:
1291 class="st">"""Return all test items collected from the module.

Calls 1

getitemsMethod · 0.95

Tested by

no test coverage detected