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

Method run

src/_pytest/pytester.py:1387–1471  ·  src/_pytest/pytester.py::Pytester.run

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,
    )

Source from the content-addressed store, hash-verified

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

Callers 15

runpythonMethod · 0.95
runpython_cMethod · 0.95
runpytest_subprocessMethod · 0.95
get_open_filesMethod · 0.45
matching_platformMethod · 0.45
runtestMethod · 0.45
dumpsMethod · 0.45
load_and_is_trueMethod · 0.45
bench.pyFile · 0.45

Calls 10

popenMethod · 0.95
_dump_linesMethod · 0.95
elapsedMethod · 0.95
ExitCodeClass · 0.90
RunResultClass · 0.85
fspathMethod · 0.80
openMethod · 0.80
closeMethod · 0.45
flushMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected