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

Method popen

src/_pytest/pytester.py:1308–1344  ·  view source on GitHub ↗

Invoke :py:class:`subprocess.Popen`. Calls :py:class:`subprocess.Popen` making sure the current working directory is in ``PYTHONPATH``. You probably want to use :py:meth:`run` instead.

(
        self,
        cmdargs: Sequence[Union[str, "os.PathLike[str]"]],
        stdout: Union[int, TextIO] = subprocess.PIPE,
        stderr: Union[int, TextIO] = subprocess.PIPE,
        stdin: Union[NotSetType, bytes, IO[Any], int] = CLOSE_STDIN,
        **kw,
    )

Source from the content-addressed store, hash-verified

1306 return None
1307
1308 def popen(
1309 self,
1310 cmdargs: Sequence[Union[str, "os.PathLike[str]"]],
1311 stdout: Union[int, TextIO] = subprocess.PIPE,
1312 stderr: Union[int, TextIO] = subprocess.PIPE,
1313 stdin: Union[NotSetType, bytes, IO[Any], int] = CLOSE_STDIN,
1314 **kw,
1315 ):
1316 """Invoke :py:class:`subprocess.Popen`.
1317
1318 Calls :py:class:`subprocess.Popen` making sure the current working
1319 directory is in ``PYTHONPATH``.
1320
1321 You probably want to use :py:meth:`run` instead.
1322 """
1323 env = os.environ.copy()
1324 env["PYTHONPATH"] = os.pathsep.join(
1325 filter(None, [os.getcwd(), env.get("PYTHONPATH", "")])
1326 )
1327 kw["env"] = env
1328
1329 if stdin is self.CLOSE_STDIN:
1330 kw["stdin"] = subprocess.PIPE
1331 elif isinstance(stdin, bytes):
1332 kw["stdin"] = subprocess.PIPE
1333 else:
1334 kw["stdin"] = stdin
1335
1336 popen = subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw)
1337 if stdin is self.CLOSE_STDIN:
1338 assert popen.stdin is not None
1339 popen.stdin.close()
1340 elif isinstance(stdin, bytes):
1341 assert popen.stdin is not None
1342 popen.stdin.write(stdin)
1343
1344 return popen
1345
1346 def run(
1347 self,

Callers 4

runMethod · 0.95
test_popen_stdin_pipeFunction · 0.45
test_popen_stdin_bytesFunction · 0.45

Calls 3

getMethod · 0.45
closeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected