Skip to content

Commit 6c7189f

Browse files
authored
Skip tests that require scipy if not available (#1201)
1 parent 7253e81 commit 6c7189f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test/test_datasets.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
cityscapes_root, svhn_root
1212

1313

14+
try:
15+
import scipy
16+
HAS_SCIPY = True
17+
except ImportError:
18+
HAS_SCIPY = False
19+
20+
1421
class Tester(unittest.TestCase):
1522
def generic_classification_dataset_test(self, dataset, num_images=1):
1623
self.assertEqual(len(dataset), num_images)
@@ -101,6 +108,7 @@ def test_fashionmnist(self, mock_download_extract):
101108
self.assertEqual(dataset.class_to_idx[dataset.classes[0]], target)
102109

103110
@mock.patch('torchvision.datasets.utils.download_url')
111+
@unittest.skipIf(not HAS_SCIPY, "scipy unavailable")
104112
def test_imagenet(self, mock_download):
105113
with imagenet_root() as root:
106114
dataset = torchvision.datasets.ImageNet(root, split='train', download=True)
@@ -187,6 +195,7 @@ def test_cityscapes(self):
187195
self.assertTrue(isinstance(output[1][2], PIL.Image.Image)) # color
188196

189197
@mock.patch('torchvision.datasets.SVHN._check_integrity')
198+
@unittest.skipIf(not HAS_SCIPY, "scipy unavailable")
190199
def test_svhn(self, mock_check):
191200
mock_check.return_value = True
192201
with svhn_root() as root:

0 commit comments

Comments
 (0)