File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Expand file tree Collapse file tree 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
2828combine_star = true
2929filter_files = true
3030
31- known_third_party = [" pytest" ]
31+ known_third_party = [" pytest" , " _pytest " ]
3232known_first_party = [" torch" , " pytest_pytorch" ]
3333known_local_folder = [" tests" ]
3434
Original file line number Diff line number Diff line change 11import re
22import unittest .mock
3+ import warnings
34from typing import Pattern
45
56from _pytest .unittest import TestCaseFunction , UnitTestCase
67
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
925
1026
1127class PytestPyTorchInternalError (Exception ):
@@ -93,6 +109,9 @@ def collect(self):
93109
94110
95111def pytest_pycollect_makeitem (collector , name , obj ):
112+ if not TORCH_AVAILABLE :
113+ return None
114+
96115 try :
97116 if (
98117 not issubclass (obj , PyTorchTestCaseTemplate )
Original file line number Diff line number Diff line change @@ -31,7 +31,6 @@ include_package_data = True
3131python_requires = >=3.6
3232install_requires =
3333 pytest
34- torch
3534
3635[options.packages.find]
3736exclude =
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ pytorch_channel = nightly
2828deps =
2929 pytest >= 6
3030 pytest-mock >= 3.1
31+ torch
3132 # The nightlies do not specify numpy as requirement
3233 numpy
3334commands =
You can’t perform that action at this time.
0 commit comments