(
python: str, test_file: str, tmpdir: pathlib.Path
)
| 86 | |
| 87 | @contextlib.contextmanager |
| 88 | def spawn_child_process( |
| 89 | python: str, test_file: str, tmpdir: pathlib.Path |
| 90 | ) -> Generator["subprocess.Popen[str]", None, None]: |
| 91 | fifo = tmpdir / "the_fifo" |
| 92 | os.mkfifo(fifo) |
| 93 | with subprocess.Popen( |
| 94 | [python, test_file, str(fifo)], |
| 95 | stdout=subprocess.PIPE, |
| 96 | stderr=subprocess.PIPE, |
| 97 | text=True, |
| 98 | ) as process: |
| 99 | with open(fifo, "r") as fifo_file: |
| 100 | response = fifo_file.read() |
| 101 | |
| 102 | assert response == "ready" |
| 103 | time.sleep(0.1) |
| 104 | try: |
| 105 | yield process |
| 106 | finally: |
| 107 | os.remove(fifo) |
| 108 | process.terminate() |
| 109 | process.kill() |
| 110 | process.wait(timeout=TIMEOUT) |
| 111 | |
| 112 | |
| 113 | @contextlib.contextmanager |
no outgoing calls