Skip to content

Commit c5b5a3e

Browse files
authored
test: Improve settings.py (#500)
1 parent 5e4d26d commit c5b5a3e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tests/settings.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
import torch
44

5+
_POSSIBLE_TEST_DEVICES = {"cpu", "cuda:0"}
6+
_POSSIBLE_TEST_DTYPES = {"float32", "float64"}
7+
58
try:
69
_device_str = os.environ["PYTEST_TORCH_DEVICE"]
710
except KeyError:
811
_device_str = "cpu" # Default to cpu if environment variable not set
912

10-
if _device_str != "cuda:0" and _device_str != "cpu":
11-
raise ValueError(f"Invalid value of environment variable PYTEST_TORCH_DEVICE: {_device_str}")
13+
if _device_str not in _POSSIBLE_TEST_DEVICES:
14+
raise ValueError(
15+
f"Invalid value of environment variable PYTEST_TORCH_DEVICE: {_device_str}.\n"
16+
f"Possible values: {_POSSIBLE_TEST_DEVICES}."
17+
)
1218

1319
if _device_str == "cuda:0" and not torch.cuda.is_available():
1420
raise ValueError('Requested device "cuda:0" but cuda is not available.')
1521

1622
DEVICE = torch.device(_device_str)
1723

18-
19-
_POSSIBLE_TEST_DTYPES = {"float32", "float64"}
20-
2124
try:
2225
_dtype_str = os.environ["PYTEST_TORCH_DTYPE"]
2326
except KeyError:

0 commit comments

Comments
 (0)