diff --git a/e2e/features/molecular/test_genes.py b/e2e/features/molecular/test_genes.py index f028c1d0..17274abe 100644 --- a/e2e/features/molecular/test_genes.py +++ b/e2e/features/molecular/test_genes.py @@ -1,6 +1,27 @@ import pytest -import siibra from typing import Union, List +from json import JSONDecodeError +from functools import wraps +import siibra + + +def skip_if_allen_api_unavailable(test_func): + @wraps(test_func) + def wrapper(*args, **kwargs): + try: + return test_func(*args, **kwargs) + except JSONDecodeError: + pytest.skip( + f"Skipping test {test_func.__name__} due to JSONDecodeError since Allen API sent a malformed JSON" + ) + except RuntimeError as e: + if str(e) == "Allen institute site unavailable - please try again later.": + pytest.skip("Skipping since Allen Institute API is unavailable.") + else: + raise e + + return wrapper + test_params = [ ("julich 2.9", "hoc1 left", "MAOA"), @@ -13,6 +34,7 @@ @pytest.mark.parametrize("parc_spec, region_spec, gene", test_params) +@skip_if_allen_api_unavailable def test_genes(parc_spec: str, region_spec: str, gene: Union[str, List[str]]): parc = siibra.parcellations[parc_spec] region = parc.get_region(region_spec) @@ -23,6 +45,7 @@ def test_genes(parc_spec: str, region_spec: str, gene: Union[str, List[str]]): ), "expecting all features to be of type GeneExpression" +@skip_if_allen_api_unavailable def test_gene_exp_w_parent_structures(): kwargs = {"gene": "MAOA"} features_grandparent_struct = siibra.features.get(