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

Method getmodulecol

src/_pytest/pytester.py:1256–1288  ·  view source on GitHub ↗

Return the module collection node for ``source``. Writes ``source`` to a file using :py:meth:`makepyfile` and then runs the pytest collection on it, returning the collection node for the test module. :param source: The source code of the module to collec

(
        self,
        source: Union[str, "os.PathLike[str]"],
        configargs=(),
        *,
        withinit: bool = False,
    )

Source from the content-addressed store, hash-verified

1254 return self.genitems([modcol])
1255
1256 def getmodulecol(
1257 self,
1258 source: Union[str, "os.PathLike[str]"],
1259 configargs=(),
1260 *,
1261 withinit: bool = False,
1262 ):
1263 """Return the module collection node for ``source``.
1264
1265 Writes ``source`` to a file using :py:meth:`makepyfile` and then
1266 runs the pytest collection on it, returning the collection node for the
1267 test module.
1268
1269 :param source:
1270 The source code of the module to collect.
1271
1272 :param configargs:
1273 Any extra arguments to pass to :py:meth:`parseconfigure`.
1274
1275 :param withinit:
1276 Whether to also write an ``__init__.py`` file to the same
1277 directory to ensure it is a package.
1278 """
1279 if isinstance(source, os.PathLike):
1280 path = self.path.joinpath(source)
1281 assert not withinit, "not supported for paths"
1282 else:
1283 kw = {self._name: str(source)}
1284 path = self.makepyfile(**kw)
1285 if withinit:
1286 self.makepyfile(__init__="#")
1287 self.config = config = self.parseconfigure(path, *configargs)
1288 return self.getnode(config, path)
1289
1290 def collect_by_name(
1291 self, modcol: Collector, name: str

Callers 15

getitemsMethod · 0.95
test_internalerrorMethod · 0.45
test_writelineMethod · 0.45
test_make_hook_recorderFunction · 0.45
test_check_equalityMethod · 0.45
test_no_underMethod · 0.45
test_collect_resultMethod · 0.45
test_failing_importMethod · 0.45

Calls 3

makepyfileMethod · 0.95
parseconfigureMethod · 0.95
getnodeMethod · 0.95

Tested by

no test coverage detected