Skip to content

Commit 1b21bcc

Browse files
author
shijiashuai
committed
test: skip GPU tests when PyTorch is missing
Keep the test suite reporting an intentional skip instead of crashing in environments without torch.
1 parent 2bad969 commit 1b21bcc

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"""
44

55
import pytest
6-
import torch
76
import numpy as np
87

8+
try:
9+
import torch
10+
except ImportError: # pragma: no cover - environment-dependent guard
11+
pytest.skip("PyTorch is not installed", allow_module_level=True)
12+
913

1014
def pytest_configure(config):
1115
"""Configure pytest markers."""

tests/test_attention.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
"""
55

66
import pytest
7-
import torch
87
from hypothesis import given, settings, strategies as st
98

9+
try:
10+
import torch
11+
except ImportError: # pragma: no cover - environment-dependent guard
12+
pytest.skip("PyTorch is not installed", allow_module_level=True)
13+
1014
from conftest import assert_close, compute_attention_reference
1115

1216

tests/test_gemm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
"""
55

66
import pytest
7-
import torch
87
from hypothesis import given, settings, strategies as st
98

9+
try:
10+
import torch
11+
except ImportError: # pragma: no cover - environment-dependent guard
12+
pytest.skip("PyTorch is not installed", allow_module_level=True)
13+
1014
from conftest import assert_close
1115

1216

tests/test_interface.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
"""
55

66
import pytest
7-
import torch
87
from hypothesis import given, settings, strategies as st
98

9+
try:
10+
import torch
11+
except ImportError: # pragma: no cover - environment-dependent guard
12+
pytest.skip("PyTorch is not installed", allow_module_level=True)
13+
1014
from conftest import assert_close
1115

1216

0 commit comments

Comments
 (0)