File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 11# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33
4+ import os
45from collections import namedtuple
6+ from contextlib import contextmanager
57
68import pytest
79from cuda .bindings import _nvml as nvml
@@ -128,3 +130,12 @@ def pci_info(ngpus, handles):
128130 pci_info = [nvml .device_get_pci_info_v3 (handles [i ]) for i in range (ngpus )]
129131 assert len (pci_info ) == ngpus
130132 return pci_info
133+
134+
135+ @contextmanager
136+ def requires_root ():
137+ if os .geteuid () == 0 :
138+ yield
139+ else :
140+ with pytest .raises (nvml .NoPermissionError ):
141+ yield
Original file line number Diff line number Diff line change 77import pytest
88from cuda .bindings import _nvml as nvml
99
10+ from . import conftest
11+
1012COMPUTE_MODES = [
1113 nvml .ComputeMode .COMPUTEMODE_DEFAULT ,
1214 nvml .ComputeMode .COMPUTEMODE_PROHIBITED ,
@@ -25,7 +27,7 @@ def test_compute_mode_supported_nonroot(all_devices):
2527 continue
2628
2729 for cm in COMPUTE_MODES :
28- with pytest . raises ( nvml . NoPermissionError ):
30+ with conftest . requires_root ( ):
2931 nvml .device_set_compute_mode (device , cm )
3032 assert original_compute_mode == nvml .device_get_compute_mode (device ), "Compute mode shouldn't have changed"
3133
You can’t perform that action at this time.
0 commit comments