Skip to content

Commit bcac5cd

Browse files
committed
Add pytest info_summary_append fixture and use from test_path_finder.py to report the absolute paths of the loaded libraries.
1 parent b3cd45b commit bcac5cd

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

‎cuda_bindings/tests/conftest.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
4+
def pytest_configure(config):
5+
config.custom_info = []
6+
7+
8+
def pytest_terminal_summary(terminalreporter, exitstatus, config):
9+
if config.custom_info:
10+
terminalreporter.write_sep("=", "INFO summary")
11+
for msg in config.custom_info:
12+
terminalreporter.line(f"INFO {msg}")
13+
14+
15+
@pytest.fixture
16+
def info_summary_append(request):
17+
def _append(message):
18+
request.config.custom_info.append(f"{request.node.name}: {message}")
19+
20+
return _append

‎cuda_bindings/tests/test_path_finder.py‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def test_all_libnames_expected_lib_symbols_consistency():
3030
assert tuple(sorted(ALL_LIBNAMES)) == tuple(sorted(supported_libs.EXPECTED_LIB_SYMBOLS.keys()))
3131

3232

33+
def _check_nvjitlink_usable():
34+
from cuda.bindings._internal import nvjitlink as inner_nvjitlink
35+
36+
return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0
37+
38+
3339
def _build_subprocess_failed_for_libname_message(libname, result):
3440
return (
3541
f"Subprocess failed for {libname=!r} with exit code {result.returncode}\n"
@@ -38,15 +44,9 @@ def _build_subprocess_failed_for_libname_message(libname, result):
3844
)
3945

4046

41-
def _check_nvjitlink_usable():
42-
from cuda.bindings._internal import nvjitlink as inner_nvjitlink
43-
44-
return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0
45-
46-
4747
@pytest.mark.parametrize("api", ("find", "load"))
4848
@pytest.mark.parametrize("libname", TEST_LIBNAMES)
49-
def test_find_or_load_nvidia_dynamic_library(api, libname):
49+
def test_find_or_load_nvidia_dynamic_library(info_summary_append, api, libname):
5050
if sys.platform == "win32" and not supported_libs.SUPPORTED_WINDOWS_DLLS[libname]:
5151
pytest.skip(f"{libname=!r} not supported on {sys.platform=}")
5252

@@ -56,7 +56,8 @@ def test_find_or_load_nvidia_dynamic_library(api, libname):
5656
if api == "find":
5757
code = f"""\
5858
from cuda.bindings._path_finder.find_nvidia_dynamic_library import find_nvidia_dynamic_library
59-
find_nvidia_dynamic_library({libname!r})
59+
abs_path = find_nvidia_dynamic_library({libname!r})
60+
print(f"{{abs_path!r}}")
6061
"""
6162
else:
6263
code = f"""\
@@ -76,12 +77,16 @@ def test_find_or_load_nvidia_dynamic_library(api, libname):
7677
raise RuntimeError("loaded_dl_no_cache.was_already_loaded_from_elsewhere")
7778
if loaded_dl_no_cache.abs_path != loaded_dl_fresh.abs_path:
7879
raise RuntimeError(f"{{loaded_dl_no_cache.abs_path=!r}} != {{loaded_dl_fresh.abs_path=!r}}")
80+
81+
print(f"{{loaded_dl_fresh.abs_path!r}}")
7982
"""
8083
result = subprocess.run( # nosec B603
8184
[sys.executable, "-c", code],
8285
stdout=subprocess.PIPE,
8386
stderr=subprocess.PIPE,
8487
encoding="utf-8",
8588
)
86-
if result.returncode != 0:
89+
if result.returncode == 0:
90+
info_summary_append(f"abs_path={result.stdout.rstrip()}")
91+
else:
8792
raise RuntimeError(_build_subprocess_failed_for_libname_message(libname, result))

0 commit comments

Comments
 (0)