Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 70f93b7

Browse files
authored
Add try statement for VOC tests on url error (#290)
* Add try statement for VOC tests on url error * fix voc tests with styling Co-authored-by: Mark Kurtz <[email protected]>
1 parent ebf9ff3 commit 70f93b7

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

tests/sparseml/pytorch/datasets/detection/test_voc.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
15+
import logging
16+
from urllib.error import URLError
1617

1718
import pytest
1819
import torch
@@ -32,40 +33,29 @@ def _validate_voc(dataset: Dataset, size: int):
3233
assert len(item[1]) == 2
3334

3435

35-
@pytest.mark.skipif(
36-
os.getenv("NM_ML_SKIP_PYTORCH_TESTS", False),
37-
reason="Skipping pytorch tests",
38-
)
3936
@pytest.mark.skipif(
4037
version.parse(torch.__version__) < version.parse("1.2"),
4138
reason="Must install pytorch version 1.2 or greater",
4239
)
43-
@pytest.mark.skipif(
44-
os.getenv("NM_ML_SKIP_DATASET_TESTS", False),
45-
reason="Skipping dataset tests",
46-
)
4740
def test_voc_detection():
48-
train_dataset = VOCDetectionDataset(train=True)
49-
_validate_voc(train_dataset, 300)
41+
try:
42+
train_dataset = VOCDetectionDataset(train=True)
43+
_validate_voc(train_dataset, 300)
5044

51-
val_dataset = VOCDetectionDataset(train=False)
52-
_validate_voc(val_dataset, 300)
45+
val_dataset = VOCDetectionDataset(train=False)
46+
_validate_voc(val_dataset, 300)
5347

54-
reg_dataset = DatasetRegistry.create("voc_det", train=False)
55-
_validate_voc(reg_dataset, 300)
48+
reg_dataset = DatasetRegistry.create("voc_det", train=False)
49+
_validate_voc(reg_dataset, 300)
50+
except URLError as err:
51+
# handle case for VOC server being down,
52+
# we should not fail our tests on an upstream we can't control
53+
logging.warning(f"Skipped VOC tests because of URLError: {err}")
5654

5755

58-
@pytest.mark.skipif(
59-
os.getenv("NM_ML_SKIP_PYTORCH_TESTS", False),
60-
reason="Skipping pytorch tests",
61-
)
6256
@pytest.mark.skipif(
6357
version.parse(torch.__version__) < version.parse("1.2"),
6458
reason="Must install pytorch version 1.2 or greater",
6559
)
66-
@pytest.mark.skipif(
67-
os.getenv("NM_ML_SKIP_DATASET_TESTS", False),
68-
reason="Skipping dataset tests",
69-
)
7060
def test_voc_segmentation():
7161
pass

0 commit comments

Comments
 (0)