Runs the given code in a subprocess.
(code: str, *, rerun: int = 8)
| 46 | |
| 47 | |
| 48 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected