| 459 | |
| 460 | |
| 461 | def get_work_dir(parent_dir: StrPath, worker: bool = False) -> StrPath: |
| 462 | # Define a writable temp dir that will be used as cwd while running |
| 463 | # the tests. The name of the dir includes the pid to allow parallel |
| 464 | # testing (see the -j option). |
| 465 | # Emscripten and WASI have stubbed getpid(), Emscripten has only |
| 466 | # millisecond clock resolution. Use randint() instead. |
| 467 | if support.is_emscripten or support.is_wasi: |
| 468 | nounce = random.randint(0, 1_000_000) |
| 469 | else: |
| 470 | nounce = os.getpid() |
| 471 | |
| 472 | if worker: |
| 473 | work_dir = WORK_DIR_PREFIX + str(nounce) |
| 474 | else: |
| 475 | work_dir = WORKER_WORK_DIR_PREFIX + str(nounce) |
| 476 | work_dir += os_helper.FS_NONASCII |
| 477 | work_dir = os.path.join(parent_dir, work_dir) |
| 478 | return work_dir |
| 479 | |
| 480 | |
| 481 | @contextlib.contextmanager |