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

Method runpytest_subprocess

src/_pytest/pytester.py:1491–1521  ·  view source on GitHub ↗

Run pytest as a subprocess with given arguments. Any plugins added to the :py:attr:`plugins` list will be added using the ``-p`` command line option. Additionally ``--basetemp`` is used to put any temporary files and directories in a numbered directory prefixed with

(
        self, *args: str | os.PathLike[str], timeout: float | None = None
    )

Source from the content-addressed store, hash-verified

1489 return self.run(sys.executable, "-c", command)
1490
1491 def runpytest_subprocess(
1492 self, *args: str | os.PathLike[str], timeout: float | None = None
1493 ) -> RunResult:
1494 """Run pytest as a subprocess with given arguments.
1495
1496 Any plugins added to the :py:attr:`plugins` list will be added using the
1497 ``-p`` command line option. Additionally ``--basetemp`` is used to put
1498 any temporary files and directories in a numbered directory prefixed
1499 with "runpytest-" to not conflict with the normal numbered pytest
1500 location for temporary files and directories.
1501
1502 :param args:
1503 The sequence of arguments to pass to the pytest subprocess.
1504 :param timeout:
1505 The period in seconds after which to timeout and raise
1506 :py:class:`Pytester.TimeoutExpired`.
1507 :returns:
1508 The result.
1509 """
1510 __tracebackhide__ = True
1511 p = make_numbered_dir(root=self.path, prefix="runpytest-", mode=0o700)
1512 args = (f"--basetemp={p}", *args)
1513 for plugin in self.plugins:
1514 if not isinstance(plugin, str):
1515 raise ValueError(
1516 f"Specifying plugins as objects is not supported in pytester subprocess mode; "
1517 f"specify by name instead: {plugin}"
1518 )
1519 args = ("-p", plugin, *args)
1520 args = self._getpytestargs() + args
1521 return self.run(*args, timeout=timeout)
1522
1523 def spawn_pytest(self, string: str, expect_timeout: float = 10.0) -> pexpect.spawn:
1524 """Run pytest using pexpect.

Calls 3

_getpytestargsMethod · 0.95
runMethod · 0.95
make_numbered_dirFunction · 0.90

Tested by

no test coverage detected