From c4b67e0cadf8cc6a710c9813d7d28d9b7f581967 Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 27 Apr 2026 17:33:56 +0000 Subject: [PATCH 1/7] Skip Pubchem live API test in CI Even with many retries and long delays, the test fails for almost every PR. I don't know why; perhaps Pubchem's servers have become overloaded lately (plausibly due to the increase in the use of AI agents). There seems to be no good solution except to simply skip the test in CI. --- src/openfermion/chem/pubchem_test.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index a1d97a86e..1f9da6a17 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -12,9 +12,11 @@ """Tests for pubchem.py.""" +import os + import numpy -import pytest import pubchempy +import pytest from openfermion.chem.pubchem import geometry_from_pubchem from openfermion.testing.testing_utils import module_importable @@ -74,6 +76,12 @@ def mock_get_compounds(name, searchtype, record_type='2d'): module_importable('pubchempy') is False, reason='Not detecting `pubchempy`.' ) +# Skip if running in a CI environment. +skip_in_ci = pytest.mark.skipif( + os.environ.get('CI') == 'true', + reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', +) + @using_pubchempy class TestOpenFermionPubChem: @@ -149,7 +157,8 @@ def test_water_2d(self, monkeypatch): with pytest.raises(ValueError, match='Incorrect value for the argument structure'): _ = geometry_from_pubchem('water', structure='foo') - @pytest.mark.flaky(retries=8, delay=30, only_on=[pubchempy.ServerBusyError]) + @skip_in_ci + @pytest.mark.flaky(retries=4, delay=30, only_on=[pubchempy.ServerBusyError]) def test_geometry_from_pubchem_live_api(self): water_geometry = geometry_from_pubchem('water') assert len(water_geometry) == 3 From ba7520693a79db99d5964ba4e02a2ca68053e96f Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Mon, 27 Apr 2026 11:19:57 -0700 Subject: [PATCH 2/7] Follow GCA's suggestion to make the environment test more robust Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/openfermion/chem/pubchem_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index 1f9da6a17..87cc8cc49 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -78,7 +78,7 @@ def mock_get_compounds(name, searchtype, record_type='2d'): # Skip if running in a CI environment. skip_in_ci = pytest.mark.skipif( - os.environ.get('CI') == 'true', +os.environ.get('CI'), reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', ) From 8174b5f93158ff45d9d526c1d38bffa78594edb0 Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 27 Apr 2026 18:21:16 +0000 Subject: [PATCH 3/7] Leave the number of retries at 8 I don't know why I thought it would be better to reduce it to 4. --- src/openfermion/chem/pubchem_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index 87cc8cc49..b4449cf09 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -158,7 +158,7 @@ def test_water_2d(self, monkeypatch): _ = geometry_from_pubchem('water', structure='foo') @skip_in_ci - @pytest.mark.flaky(retries=4, delay=30, only_on=[pubchempy.ServerBusyError]) + @pytest.mark.flaky(retries=8, delay=30, only_on=[pubchempy.ServerBusyError]) def test_geometry_from_pubchem_live_api(self): water_geometry = geometry_from_pubchem('water') assert len(water_geometry) == 3 From ca95ad0c07f703bdbb11cb52e55eebd5bc2d4369 Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 27 Apr 2026 18:28:31 +0000 Subject: [PATCH 4/7] Format --- src/openfermion/chem/pubchem_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index b4449cf09..b17b72f90 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -78,7 +78,7 @@ def mock_get_compounds(name, searchtype, record_type='2d'): # Skip if running in a CI environment. skip_in_ci = pytest.mark.skipif( -os.environ.get('CI'), + os.environ.get('CI'), reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', ) From c7a46e53f73e400a442f581ebe51ab1a2d2564bb Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 27 Apr 2026 21:42:00 +0000 Subject: [PATCH 5/7] Fix copmarison in pytest.mark.skipif --- src/openfermion/chem/pubchem_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index b17b72f90..1fc17d632 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -78,7 +78,7 @@ def mock_get_compounds(name, searchtype, record_type='2d'): # Skip if running in a CI environment. skip_in_ci = pytest.mark.skipif( - os.environ.get('CI'), + os.environ.get('CI', False) != False, reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', ) From 52ca2255fb186e72654dc9933772d4d200e3c202 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Mon, 27 Apr 2026 15:55:24 -0700 Subject: [PATCH 6/7] Do better test for `CI` in environment Co-authored-by: Pavol Juhas --- src/openfermion/chem/pubchem_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index 1fc17d632..940e14f22 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -78,7 +78,7 @@ def mock_get_compounds(name, searchtype, record_type='2d'): # Skip if running in a CI environment. skip_in_ci = pytest.mark.skipif( - os.environ.get('CI', False) != False, + 'CI' in os.environ, reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', ) From 5ed6840046ef22d130f2ca1c210551e17a3982bf Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 27 Apr 2026 23:00:14 +0000 Subject: [PATCH 7/7] Don't bother defining skip_in_ci; just use the test As suggested by Pavol in review. --- src/openfermion/chem/pubchem_test.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/openfermion/chem/pubchem_test.py b/src/openfermion/chem/pubchem_test.py index 940e14f22..5834b337c 100644 --- a/src/openfermion/chem/pubchem_test.py +++ b/src/openfermion/chem/pubchem_test.py @@ -76,12 +76,6 @@ def mock_get_compounds(name, searchtype, record_type='2d'): module_importable('pubchempy') is False, reason='Not detecting `pubchempy`.' ) -# Skip if running in a CI environment. -skip_in_ci = pytest.mark.skipif( - 'CI' in os.environ, - reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', -) - @using_pubchempy class TestOpenFermionPubChem: @@ -157,7 +151,11 @@ def test_water_2d(self, monkeypatch): with pytest.raises(ValueError, match='Incorrect value for the argument structure'): _ = geometry_from_pubchem('water', structure='foo') - @skip_in_ci + # Skip if running in a CI environment. + @pytest.mark.skipif( + 'CI' in os.environ, + reason='Skipping Pubchem API tests in CI to avoid failures due to busy servers.', + ) @pytest.mark.flaky(retries=8, delay=30, only_on=[pubchempy.ServerBusyError]) def test_geometry_from_pubchem_live_api(self): water_geometry = geometry_from_pubchem('water')