File tree 4 files changed +23
-4
lines changed
4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ order_by_type = true
28
28
combine_star = true
29
29
filter_files = true
30
30
31
- known_third_party = [" pytest" ]
31
+ known_third_party = [" pytest" , " _pytest " ]
32
32
known_first_party = [" torch" , " pytest_pytorch" ]
33
33
known_local_folder = [" tests" ]
34
34
Original file line number Diff line number Diff line change 1
1
import re
2
2
import unittest .mock
3
+ import warnings
3
4
from typing import Pattern
4
5
5
6
from _pytest .unittest import TestCaseFunction , UnitTestCase
6
7
7
- from torch .testing ._internal .common_device_type import get_device_type_test_bases
8
- from torch .testing ._internal .common_utils import TestCase as PyTorchTestCaseTemplate
8
+ try :
9
+ from torch .testing ._internal .common_device_type import get_device_type_test_bases
10
+ from torch .testing ._internal .common_utils import TestCase as PyTorchTestCaseTemplate
11
+
12
+ TORCH_AVAILABLE = True
13
+ except ImportError :
14
+ TORCH_AVAILABLE = False
15
+
16
+ warnings .warn (
17
+ "Disabling the plugin 'pytest-pytorch', because 'torch' could not be imported."
18
+ )
19
+
20
+ def get_device_type_test_bases ():
21
+ return []
22
+
23
+ class PyTorchTestCaseTemplate :
24
+ pass
9
25
10
26
11
27
class PytestPyTorchInternalError (Exception ):
@@ -93,6 +109,9 @@ def collect(self):
93
109
94
110
95
111
def pytest_pycollect_makeitem (collector , name , obj ):
112
+ if not TORCH_AVAILABLE :
113
+ return None
114
+
96
115
try :
97
116
if (
98
117
not issubclass (obj , PyTorchTestCaseTemplate )
Original file line number Diff line number Diff line change @@ -31,7 +31,6 @@ include_package_data = True
31
31
python_requires = >=3.6
32
32
install_requires =
33
33
pytest
34
- torch
35
34
36
35
[options.packages.find]
37
36
exclude =
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ pytorch_channel = nightly
28
28
deps =
29
29
pytest >= 6
30
30
pytest-mock >= 3.1
31
+ torch
31
32
# The nightlies do not specify numpy as requirement
32
33
numpy
33
34
commands =
You can’t perform that action at this time.
0 commit comments