|
1 | | -# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | 4 | # If we have subcategories of examples in the future, this file can be split along those lines |
5 | 5 |
|
6 | 6 | import glob |
7 | 7 | import os |
| 8 | +import subprocess |
| 9 | +import sys |
8 | 10 |
|
9 | 11 | import pytest |
10 | 12 |
|
11 | | -from cuda.core import Device |
12 | | - |
13 | | -from .utils import run_example |
| 13 | +DISALLOW_LIST = { |
| 14 | + "gl_interop_plasma.py", # requires a display |
| 15 | +} |
14 | 16 |
|
15 | 17 | samples_path = os.path.join(os.path.dirname(__file__), "..", "..", "examples") |
16 | | -sample_files = glob.glob(samples_path + "**/*.py", recursive=True) |
| 18 | +sample_files = [ |
| 19 | + x |
| 20 | + for x in (os.path.basename(x) for x in glob.glob(samples_path + "**/*.py", recursive=True)) |
| 21 | + if x not in DISALLOW_LIST |
| 22 | +] |
17 | 23 |
|
18 | 24 |
|
19 | 25 | @pytest.mark.parametrize("example", sample_files) |
20 | 26 | class TestExamples: |
21 | | - def test_example(self, example, deinit_cuda): |
22 | | - run_example(samples_path, example) |
23 | | - if Device().device_id != 0: |
24 | | - Device(0).set_current() |
| 27 | + def test_example(self, example): |
| 28 | + example_path = os.path.join(samples_path, example) |
| 29 | + process = subprocess.run([sys.executable, example_path], capture_output=True) # noqa: S603 |
| 30 | + if process.returncode != 0: |
| 31 | + print(process.stdout.decode()) |
| 32 | + print(process.stderr.decode(), file=sys.stderr) |
| 33 | + raise AssertionError(f"Example failed with return code {process.returncode} ({example})") |
0 commit comments