From 6cbdaf24c4faf755426fb08ffcd9e86e208972d6 Mon Sep 17 00:00:00 2001 From: Fabrice Normandin Date: Wed, 20 Nov 2024 15:36:06 +0000 Subject: [PATCH] Add skip mark for macOS tests in CI Signed-off-by: Fabrice Normandin --- project/algorithms/image_classifier_test.py | 12 +++--------- project/algorithms/jax_image_classifier_test.py | 2 ++ project/conftest.py | 8 ++++++++ project/utils/testutils.py | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/project/algorithms/image_classifier_test.py b/project/algorithms/image_classifier_test.py index 5f88c9bb..adff120b 100644 --- a/project/algorithms/image_classifier_test.py +++ b/project/algorithms/image_classifier_test.py @@ -1,19 +1,17 @@ """Example showing how the test suite can be used to add tests for a new algorithm.""" -import sys - import pytest import torch from transformers import PreTrainedModel from project.algorithms.testsuites.lightning_module_tests import LightningModuleTests from project.configs import Config -from project.conftest import command_line_overrides +from project.conftest import command_line_overrides, skip_on_macos_in_CI from project.datamodules.image_classification.cifar10 import CIFAR10DataModule from project.datamodules.image_classification.image_classification import ( ImageClassificationDataModule, ) -from project.utils.testutils import IN_GITHUB_CI, run_for_all_configs_of_type +from project.utils.testutils import run_for_all_configs_of_type from .image_classifier import ImageClassifier @@ -33,11 +31,7 @@ def test_example_experiment_defaults(experiment_config: Config) -> None: assert isinstance(experiment_config.datamodule, CIFAR10DataModule) -@pytest.mark.skipif( - sys.platform == "darwin" and IN_GITHUB_CI, - # raises=(RuntimeError, hydra.errors.InstantiationException), - reason="Raises 'MPS backend out of memory' error on MacOS in GitHub CI.", -) +@skip_on_macos_in_CI @run_for_all_configs_of_type("algorithm", ImageClassifier) @run_for_all_configs_of_type("datamodule", ImageClassificationDataModule) @run_for_all_configs_of_type("algorithm/network", torch.nn.Module, excluding=PreTrainedModel) diff --git a/project/algorithms/jax_image_classifier_test.py b/project/algorithms/jax_image_classifier_test.py index e1cd8d20..40381bea 100644 --- a/project/algorithms/jax_image_classifier_test.py +++ b/project/algorithms/jax_image_classifier_test.py @@ -5,6 +5,7 @@ import pytest from project.algorithms.jax_image_classifier import JaxImageClassifier +from project.conftest import skip_on_macos_in_CI from project.datamodules.image_classification.image_classification import ( ImageClassificationDataModule, ) @@ -18,6 +19,7 @@ def prevent_jax_from_reserving_all_the_vram(monkeypatch: pytest.MonkeyPatch): monkeypatch.setenv("XLA_PYTHON_CLIENT_PREALLOCATE", "false") +@skip_on_macos_in_CI @run_for_all_configs_of_type("algorithm", JaxImageClassifier) @run_for_all_configs_of_type("algorithm/network", flax.linen.Module) @run_for_all_configs_of_type("datamodule", ImageClassificationDataModule) diff --git a/project/conftest.py b/project/conftest.py index 6d0abea9..c207eaff 100644 --- a/project/conftest.py +++ b/project/conftest.py @@ -103,6 +103,7 @@ from project.utils.env_vars import REPO_ROOTDIR from project.utils.hydra_utils import resolve_dictconfig from project.utils.testutils import ( + IN_GITHUB_CI, PARAM_WHEN_USED_MARK_NAME, default_marks_for_config_combinations, default_marks_for_config_name, @@ -126,6 +127,13 @@ ) +skip_on_macos_in_CI = pytest.mark.skipif( + sys.platform == "darwin" and IN_GITHUB_CI, + # raises=(RuntimeError, hydra.errors.InstantiationException), + reason="Raises 'MPS backend out of memory' error on MacOS in GitHub CI.", +) + + @pytest.fixture(autouse=True) def original_datadir(original_datadir: Path): """Overwrite the original_datadir fixture value to change where regression files are created. diff --git a/project/utils/testutils.py b/project/utils/testutils.py index cbddc0a6..82246952 100644 --- a/project/utils/testutils.py +++ b/project/utils/testutils.py @@ -24,7 +24,7 @@ IN_GITHUB_CI = "GITHUB_ACTIONS" in os.environ IN_SELF_HOSTED_GITHUB_CI = IN_GITHUB_CI and "self-hosted" in os.environ.get("RUNNER_LABELS", "") -IN_GITHUB_COULD_CI = IN_GITHUB_CI and not IN_SELF_HOSTED_GITHUB_CI +IN_GITHUB_CLOUD_CI = IN_GITHUB_CI and not IN_SELF_HOSTED_GITHUB_CI PARAM_WHEN_USED_MARK_NAME = "parametrize_when_used"