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: str | os.PathLike[str],
configargs=(),
*,
withinit: bool = False,
)
| 1297 | return self.genitems([modcol]) |
| 1298 | |
| 1299 | def getmodulecol( |
| 1300 | self, |
| 1301 | source: str | os.PathLike[str], |
| 1302 | configargs=(), |
| 1303 | *, |
| 1304 | withinit: bool = False, |
| 1305 | ): |
| 1306 | """Return the module collection node for ``source``. |
| 1307 | |
| 1308 | Writes ``source`` to a file using :py:meth:`makepyfile` and then |
| 1309 | runs the pytest collection on it, returning the collection node for the |
| 1310 | test module. |
| 1311 | |
| 1312 | :param source: |
| 1313 | The source code of the module to collect. |
| 1314 | |
| 1315 | :param configargs: |
| 1316 | Any extra arguments to pass to :py:meth:`parseconfigure`. |
| 1317 | |
| 1318 | :param withinit: |
| 1319 | Whether to also write an ``__init__.py`` file to the same |
| 1320 | directory to ensure it is a package. |
| 1321 | """ |
| 1322 | if isinstance(source, os.PathLike): |
| 1323 | path = self.path.joinpath(source) |
| 1324 | assert not withinit, "not supported for paths" |
| 1325 | else: |
| 1326 | kw = {self._name: str(source)} |
| 1327 | path = self.makepyfile(**kw) |
| 1328 | if withinit: |
| 1329 | self.makepyfile(__init__="#") |
| 1330 | self.config = config = self.parseconfigure(path, *configargs) |
| 1331 | return self.getnode(config, path) |
| 1332 | |
| 1333 | def collect_by_name(self, modcol: Collector, name: str) -> Item | Collector | None: |
| 1334 | """Return the collection node for name from the module collection. |
no test coverage detected