forked from NVIDIA/cuda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_pytest_with_stack.py
More file actions
54 lines (40 loc) · 1.29 KB
/
Copy pathrun_pytest_with_stack.py
File metadata and controls
54 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
"""Run pytest on a thread with a larger stack size.
Cython linetrace instrumentation under coverage on Windows can exceed the
default 1 MB thread stack. This helper spawns a single worker thread with
a configurable stack (default 8 MB) so the rest of the CI workflow stays
readable.
Usage:
python run_pytest_with_stack.py [--stack-mb N] [--cwd DIR] [pytest args ...]
"""
import argparse
import concurrent.futures
import os
import sys
import threading
import pytest
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--stack-mb",
type=int,
default=8,
help="Thread stack size in megabytes (default: 8)",
)
parser.add_argument(
"--cwd",
default=None,
help="Working directory for the test run",
)
args, pytest_args = parser.parse_known_args()
if args.cwd:
os.chdir(args.cwd)
threading.stack_size(args.stack_mb * 1024 * 1024)
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
code = pool.submit(pytest.main, pytest_args).result()
sys.exit(code)
if __name__ == "__main__":
main()