From 8a2302f771a366e2018ec545a043c46fc97feb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Goinvic?= Date: Wed, 25 Feb 2026 10:36:37 +0100 Subject: [PATCH] chart_from_ci_cache should not be a generator - In case of exception, it yields twice, which is invalid contextmanager behaviour --- tests/integration/fixtures/cluster.py | 44 +++++++++++++-------------- tests/integration/lib/utils.py | 10 +++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/integration/fixtures/cluster.py b/tests/integration/fixtures/cluster.py index 034c9f85..5295dd30 100644 --- a/tests/integration/fixtures/cluster.py +++ b/tests/integration/fixtures/cluster.py @@ -154,16 +154,16 @@ async def cert_manager(helm_client, kube_client): if os.environ.get("SKIP_CERT_MANAGER", "false") != "false": return - async with chart_from_ci_cache(helm_client, "oci://quay.io/jetstack/charts/cert-manager") as chart: - await helm_client.install_or_upgrade_release( - "cert-manager", - chart, - yaml.safe_load((Path(__file__).parent / "files/charts/cert-manager.yml").open()), - namespace="cert-manager", - create_namespace=True, - atomic=True, - wait=True, - ) + chart = await chart_from_ci_cache(helm_client, "oci://quay.io/jetstack/charts/cert-manager") + await helm_client.install_or_upgrade_release( + "cert-manager", + chart, + yaml.safe_load((Path(__file__).parent / "files/charts/cert-manager.yml").open()), + namespace="cert-manager", + create_namespace=True, + atomic=True, + wait=True, + ) ca_folder = Path(__file__).parent.parent.parent.parent / ".ca" if not ca_folder.exists(): @@ -230,20 +230,20 @@ async def cert_manager(helm_client, kube_client): @pytest.fixture(scope="session") async def prometheus_operator_crds(helm_client): if os.environ.get("SKIP_SERVICE_MONITORS_CRDS", "false") == "false": - async with chart_from_ci_cache( + chart = await chart_from_ci_cache( helm_client, "oci://ghcr.io/prometheus-community/charts/prometheus-operator-crds", - ) as chart: - # Install or upgrade a release - await helm_client.install_or_upgrade_release( - "prometheus-operator-crds", - chart, - {}, - namespace="prometheus-operator", - create_namespace=True, - atomic=True, - wait=True, - ) + ) + # Install or upgrade a release + await helm_client.install_or_upgrade_release( + "prometheus-operator-crds", + chart, + {}, + namespace="prometheus-operator", + create_namespace=True, + atomic=True, + wait=True, + ) @pytest.fixture(scope="session") diff --git a/tests/integration/lib/utils.py b/tests/integration/lib/utils.py index 8b12dbe1..a7a26d65 100644 --- a/tests/integration/lib/utils.py +++ b/tests/integration/lib/utils.py @@ -259,8 +259,7 @@ async def forward_matching_logs(input_logs_queue: asyncio.Queue, output_matchers output_logs_queue.put_nowait(log_line) -@asynccontextmanager -async def chart_from_ci_cache(helm_client: pyhelm3.Client, chart_ref: str) -> AsyncGenerator[pyhelm3.Chart]: +async def chart_from_ci_cache(helm_client: pyhelm3.Client, chart_ref: str) -> pyhelm3.Chart: project_root = Path(__file__).parent.parent.parent.parent if os.environ.get("CI"): helm_cache = project_root / ".pyhelm_cache" @@ -274,12 +273,13 @@ async def chart_from_ci_cache(helm_client: pyhelm3.Client, chart_ref: str) -> As shutil.rmtree(cached_ref) # pull_chart returns a Chart object, not a Path, type annotation is wrong chart.ref.copy(cached_ref) # type: ignore - yield chart # type: ignore + # pull_chart removes the pulled chart, we return the cached one + return await helm_client.get_chart(cached_ref) # type: ignore except Exception: # Fall back to cache if remote fetch fails if cached_ref.exists(): - yield await helm_client.get_chart(cached_ref) + return await helm_client.get_chart(cached_ref) else: raise # Re-raise if neither remote nor cache is available else: - yield await helm_client.get_chart(chart_ref) + return await helm_client.get_chart(chart_ref)