From 7ec0170874ffd6a2e5741e47623ff47e7b0304b1 Mon Sep 17 00:00:00 2001 From: Lukas Heumos Date: Wed, 23 Sep 2026 15:10:49 +0200 Subject: [PATCH] Make the PubChem compound annotation test robust to PubChem outages pubchempy converts PubChem 404s into empty results, so a transient outage surfaces as a "no matches" ValueError from annotate_compounds, which the retry loop did not catch (daily integration run, #1108). Retry on ValueError too, annotate a copy per attempt, and skip with the reason after the last retry instead of silently passing. --- tests/metadata/test_compound.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/metadata/test_compound.py b/tests/metadata/test_compound.py index 88fdbb7a..5beaa87e 100644 --- a/tests/metadata/test_compound.py +++ b/tests/metadata/test_compound.py @@ -42,17 +42,16 @@ def adata() -> AnnData: def test_compound_annotation(adata): retries = 3 - attempt = 0 - while attempt < retries: + for attempt in range(retries): try: - pt_compound.annotate_compounds(adata=adata, query_id="perturbation") - assert len(adata.obs.columns) == 5 - pubchemid = [5328779, 9796068, 16124208, 5280343] * NUM_CELLS_PER_ID - assert pubchemid == list(adata.obs["pubchem_ID"]) - return - except PubChemHTTPError: + annotated = pt_compound.annotate_compounds(adata=adata, query_id="perturbation", copy=True) + break + # pubchempy turns PubChem 404s into empty results, which surface as a ValueError for no matches + except (PubChemHTTPError, ValueError) as e: if attempt == retries - 1: - # Should fail but it fails too often so we just let it pass - return + pytest.skip(f"PubChem unavailable: {e}") time.sleep(10) - attempt += 1 + + assert len(annotated.obs.columns) == 5 + pubchemid = [5328779, 9796068, 16124208, 5280343] * NUM_CELLS_PER_ID + assert pubchemid == list(annotated.obs["pubchem_ID"])