MCPcopy Create free account
hub / github.com/pybind/pybind11 / check_script_success_in_subprocess

Function check_script_success_in_subprocess

tests/env.py:48–76  ·  view source on GitHub ↗

Runs the given code in a subprocess.

(code: str, *, rerun: int = 8)

Source from the content-addressed store, hash-verified

46
47
48def check_script_success_in_subprocess(code: str, *, rerun: int = 8) -> None:
49 """Runs the given code in a subprocess."""
50 import os
51 import subprocess
52 import sys
53 import textwrap
54
55 if ANDROID or IOS or sys.platform.startswith("emscripten"):
56 pytest.skip("Requires subprocess support")
57
58 code = textwrap.dedent(code).strip()
59 try:
60 for _ in range(rerun): # run flakily failing test multiple times
61 subprocess.check_output(
62 [sys.executable, "-c", code],
63 cwd=os.getcwd(),
64 stderr=subprocess.STDOUT,
65 text=True,
66 )
67 except subprocess.CalledProcessError as ex:
68 raise RuntimeError(
69 f"Subprocess failed with exit code {ex.returncode}.\n\n"
70 f"Code:\n"
71 f"```python\n"
72 f"{code}\n"
73 f"```\n\n"
74 f"Output:\n"
75 f"{ex.output}"
76 ) from None

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected