diff --git a/pyproject.toml b/pyproject.toml index aae15f17..e91ef78b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -147,4 +147,7 @@ commands = description = Run tests coredev: Run tests with the development version of cellfinder +passenv = + CI + GITHUB_* """ diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..b61cb636 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,24 @@ +import os + +import pytest +import torch +from cellfinder.core.tools.system import force_cpu + + +@pytest.fixture(scope="session", autouse=True) +def set_backend_torch(): + os.environ["KERAS_BACKEND"] = "torch" + + +@pytest.fixture(scope="session", autouse=True) +def set_device_arm_macos_ci(): + """ + Ensure that the device is set to CPU when running on arm based macOS + GitHub runners. This is to avoid the following error: + https://discuss.pytorch.org/t/mps-back-end-out-of-memory-on-github-action/189773/5 + """ + if ( + os.getenv("GITHUB_ACTIONS") == "true" + and torch.backends.mps.is_available() + ): + force_cpu()