|
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | 4 | import functools |
| 5 | +import importlib |
5 | 6 | import inspect |
6 | 7 | import pathlib |
7 | 8 | import sys |
8 | 9 | from contextlib import contextmanager |
9 | | -from importlib.metadata import PackageNotFoundError, distribution |
10 | 10 |
|
11 | 11 | import pytest |
12 | 12 |
|
13 | 13 | import cuda.bindings.driver as cuda |
14 | 14 |
|
15 | | -# Import shared test helpers for tests across subprojects. |
16 | | -# PLEASE KEEP IN SYNC with copies in other conftest.py in this repo. |
17 | | -_test_helpers_root = pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers" |
| 15 | +# Keep in sync with cuda_core/tests/conftest.py. |
18 | 16 | try: |
19 | | - distribution("cuda-python-test-helpers") |
20 | | -except PackageNotFoundError as exc: |
| 17 | + import cuda_python_test_helpers._pytest_plugin # noqa: F401 |
| 18 | +except ImportError as e: |
| 19 | + # Don't call .resolve(): resolving symlinks can make parents[2] point |
| 20 | + # somewhere other than the monorepo root if a sub-directory is symlinked. |
| 21 | + _test_helpers_root = pathlib.Path(__file__).parents[2] / "cuda_python_test_helpers" |
21 | 22 | if not _test_helpers_root.is_dir(): |
22 | | - raise RuntimeError( |
23 | | - f"cuda-python-test-helpers not installed; expected checkout path {_test_helpers_root}" |
24 | | - ) from exc |
25 | | - |
26 | | - test_helpers_root = str(_test_helpers_root) |
27 | | - if test_helpers_root not in sys.path: |
28 | | - sys.path.insert(0, test_helpers_root) |
| 23 | + raise RuntimeError(f"cuda-python-test-helpers not installed and not found at {_test_helpers_root}") from e |
| 24 | + for _k in list(sys.modules): |
| 25 | + if _k == "cuda_python_test_helpers" or _k.startswith("cuda_python_test_helpers."): |
| 26 | + del sys.modules[_k] |
| 27 | + sys.path.insert(0, str(_test_helpers_root)) |
| 28 | + importlib.invalidate_caches() |
| 29 | + |
| 30 | +pytest_plugins = ["cuda_python_test_helpers._pytest_plugin"] |
29 | 31 |
|
30 | 32 |
|
31 | 33 | def pytest_configure(config): |
|
0 commit comments