Run a command with arguments. Run a process using :py:class:`subprocess.Popen` saving the stdout and stderr. :param cmdargs: The sequence of arguments to pass to :py:class:`subprocess.Popen`, with path-like objects being converted to :py:class:`str`
(
self,
*cmdargs: str | os.PathLike[str],
timeout: float | None = None,
stdin: NotSetType | bytes | IO[Any] | int = CLOSE_STDIN,
)
| 1385 | return popen |
| 1386 | |
| 1387 | def run( |
| 1388 | self, |
| 1389 | *cmdargs: str | os.PathLike[str], |
| 1390 | timeout: float | None = None, |
| 1391 | stdin: NotSetType | bytes | IO[Any] | int = CLOSE_STDIN, |
| 1392 | ) -> RunResult: |
| 1393 | class="st">"""Run a command with arguments. |
| 1394 | |
| 1395 | Run a process using :py:class:`subprocess.Popen` saving the stdout and |
| 1396 | stderr. |
| 1397 | |
| 1398 | :param cmdargs: |
| 1399 | The sequence of arguments to pass to :py:class:`subprocess.Popen`, |
| 1400 | with path-like objects being converted to :py:class:`str` |
| 1401 | automatically. |
| 1402 | :param timeout: |
| 1403 | The period in seconds after which to timeout and raise |
| 1404 | :py:class:`Pytester.TimeoutExpired`. |
| 1405 | :param stdin: |
| 1406 | Optional standard input. |
| 1407 | |
| 1408 | - If it is ``CLOSE_STDIN`` (Default), then this method calls |
| 1409 | :py:class:`subprocess.Popen` with ``stdin=subprocess.PIPE``, and |
| 1410 | the standard input is closed immediately after the new command is |
| 1411 | started. |
| 1412 | |
| 1413 | - If it is of type :py:class:`bytes`, these bytes are sent to the |
| 1414 | standard input of the command. |
| 1415 | |
| 1416 | - Otherwise, it is passed through to :py:class:`subprocess.Popen`. |
| 1417 | For further information in this case, consult the document of the |
| 1418 | ``stdin`` parameter in :py:class:`subprocess.Popen`. |
| 1419 | :type stdin: _pytest.compat.NotSetType | bytes | IO[Any] | int |
| 1420 | :returns: |
| 1421 | The result. |
| 1422 | |
| 1423 | class="st">""" |
| 1424 | __tracebackhide__ = True |
| 1425 | |
| 1426 | cmdargs = tuple(os.fspath(arg) for arg in cmdargs) |
| 1427 | p1 = self.path.joinpath(class="st">"stdout") |
| 1428 | p2 = self.path.joinpath(class="st">"stderr") |
| 1429 | print(class="st">"running:", *cmdargs) |
| 1430 | print(class="st">" in:", Path.cwd()) |
| 1431 | |
| 1432 | with p1.open(class="st">"w", encoding=class="st">"utf8") as f1, p2.open(class="st">"w", encoding=class="st">"utf8") as f2: |
| 1433 | instant = timing.Instant() |
| 1434 | popen = self.popen( |
| 1435 | cmdargs, |
| 1436 | stdin=stdin, |
| 1437 | stdout=f1, |
| 1438 | stderr=f2, |
| 1439 | ) |
| 1440 | if popen.stdin is not None: |
| 1441 | popen.stdin.close() |
| 1442 | |
| 1443 | def handle_timeout() -> None: |
| 1444 | __tracebackhide__ = True |
no test coverage detected