diff --git a/tests/image/semantic_segm/test_backbones.py b/tests/image/semantic_segm/test_backbones.py index 4b8fb7a7a7..9a76b60061 100644 --- a/tests/image/semantic_segm/test_backbones.py +++ b/tests/image/semantic_segm/test_backbones.py @@ -19,11 +19,9 @@ @pytest.mark.parametrize( ["backbone"], - [ - pytest.param("resnet50", marks=pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP")), - pytest.param("dpn131", marks=pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP")), - ], + ["resnet50", "dpn131"], ) +@pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP") def test_semantic_segmentation_backbones_registry(backbone): backbone = SEMANTIC_SEGMENTATION_BACKBONES.get(backbone)() assert backbone diff --git a/tests/image/semantic_segm/test_data.py b/tests/image/semantic_segm/test_data.py index c865285055..d227dcb742 100644 --- a/tests/image/semantic_segm/test_data.py +++ b/tests/image/semantic_segm/test_data.py @@ -50,15 +50,14 @@ def create_random_data(image_files: List[str], label_files: List[str], size: Tup _rand_labels(size, num_classes).save(label_file) +@pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") class TestSemanticSegmentationData: @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") def test_smoke(): dm = SemanticSegmentationData(batch_size=1) assert dm is not None @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") def test_from_folders(tmpdir): tmp_dir = Path(tmpdir) @@ -120,7 +119,6 @@ def test_from_folders(tmpdir): assert labels.shape == (2, 128, 128) @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") def test_from_folders_different_extensions(tmpdir): tmp_dir = Path(tmpdir) @@ -182,7 +180,6 @@ def test_from_folders_different_extensions(tmpdir): assert labels.shape == (2, 128, 128) @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") def test_from_folders_error(tmpdir): tmp_dir = Path(tmpdir) @@ -217,7 +214,6 @@ def test_from_folders_error(tmpdir): ) @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") def test_from_files(tmpdir): tmp_dir = Path(tmpdir) @@ -276,7 +272,6 @@ def test_from_files(tmpdir): assert labels.shape == (2, 128, 128) @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") def test_from_files_warning(tmpdir): tmp_dir = Path(tmpdir) @@ -310,7 +305,6 @@ def test_from_files_warning(tmpdir): ) @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") @pytest.mark.skipif(not _FIFTYONE_AVAILABLE, reason="fiftyone is not installed for testing") def test_from_fiftyone(tmpdir): tmp_dir = Path(tmpdir) @@ -380,7 +374,6 @@ def test_from_fiftyone(tmpdir): assert imgs.shape == (2, 3, 128, 128) @staticmethod - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") @pytest.mark.skipif(not _MATPLOTLIB_AVAILABLE, reason="matplotlib isn't installed.") def test_map_labels(tmpdir): tmp_dir = Path(tmpdir) diff --git a/tests/image/semantic_segm/test_heads.py b/tests/image/semantic_segm/test_heads.py index cb18b2bfd1..0bc2ef3dcf 100644 --- a/tests/image/semantic_segm/test_heads.py +++ b/tests/image/semantic_segm/test_heads.py @@ -22,14 +22,8 @@ from flash.image.segmentation.heads import SEMANTIC_SEGMENTATION_HEADS -@pytest.mark.parametrize( - "head", - [ - pytest.param("fpn", marks=pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP")), - pytest.param("deeplabv3", marks=pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP")), - pytest.param("unet", marks=pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP")), - ], -) +@pytest.mark.parametrize("head", ["fpn", "deeplabv3", "unet"]) +@pytest.mark.skipif(not _SEGMENTATION_MODELS_AVAILABLE, reason="No SMP") def test_semantic_segmentation_heads_registry(head): img = torch.rand(1, 3, 32, 32) backbone = SEMANTIC_SEGMENTATION_BACKBONES.get("resnet50")(pretrained=False) diff --git a/tests/image/semantic_segm/test_output.py b/tests/image/semantic_segm/test_output.py index f431558e7b..6c774a6cb6 100644 --- a/tests/image/semantic_segm/test_output.py +++ b/tests/image/semantic_segm/test_output.py @@ -19,8 +19,8 @@ from flash.image.segmentation.output import FiftyOneSegmentationLabelsOutput, SegmentationLabelsOutput +@pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, "image libraries aren't installed.") class TestSemanticSegmentationLabelsOutput: - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, "image libraries aren't installed.") @staticmethod def test_smoke(): serial = SegmentationLabelsOutput() @@ -28,7 +28,6 @@ def test_smoke(): assert serial.labels_map is None assert serial.visualize is False - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, "image libraries aren't installed.") @staticmethod def test_exception(): serial = SegmentationLabelsOutput() @@ -41,7 +40,6 @@ def test_exception(): sample = torch.zeros(2, 3) serial.transform(sample) - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, "image libraries aren't installed.") @staticmethod def test_serialize(): serial = SegmentationLabelsOutput() @@ -54,7 +52,6 @@ def test_serialize(): assert torch.tensor(classes)[1, 2] == 1 assert torch.tensor(classes)[0, 1] == 3 - @pytest.mark.skipif(not _TOPIC_IMAGE_AVAILABLE, reason="image libraries aren't installed.") @pytest.mark.skipif(not _FIFTYONE_AVAILABLE, reason="fiftyone is not installed for testing") @staticmethod def test_serialize_fiftyone():