From c428ada090becfbb89a0e77fd1e7521be0cd9a92 Mon Sep 17 00:00:00 2001 From: mubashir1osmani Date: Mon, 13 Jul 2026 18:37:54 -0700 Subject: [PATCH] test(e2e): queue suite model registrations for deletion via ResourceManager build_logging_client defers each create_model into a session ResourceManager and the client fixture tears it down at session end, so re-runs and parallel workers never accumulate stale deployments --- tests/e2e/logging/conftest.py | 10 +++++++--- tests/e2e/logging/logging_client.py | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/e2e/logging/conftest.py b/tests/e2e/logging/conftest.py index fc2cc56811e..60492c9f0bd 100644 --- a/tests/e2e/logging/conftest.py +++ b/tests/e2e/logging/conftest.py @@ -7,6 +7,7 @@ Never pytest.skip from this suite for environment gaps. from __future__ import annotations import os +from collections.abc import Iterator import pytest @@ -28,11 +29,14 @@ def pytest_configure(config: pytest.Config) -> None: @pytest.fixture(scope="session") -def client() -> LoggingClient: +def client() -> Iterator[LoggingClient]: """The logging suite's client: holds the shared Gateway so `resources` / `scoped_key` clean up keys and teams, and adds `/metrics` scraping plus - Langfuse read-back.""" - return build_logging_client() + Langfuse and Phoenix read-back. The models registered at build time are + queued for deletion and removed at session end.""" + logging_client, model_cleanup = build_logging_client() + yield logging_client + model_cleanup.teardown() @pytest.fixture diff --git a/tests/e2e/logging/logging_client.py b/tests/e2e/logging/logging_client.py index 7ea956b1d29..5a0d75f3ffd 100644 --- a/tests/e2e/logging/logging_client.py +++ b/tests/e2e/logging/logging_client.py @@ -21,6 +21,7 @@ from pydantic import BaseModel, ConfigDict, Field, JsonValue, RootModel, TypeAda from e2e_config import POLL_INTERVAL, POLL_TIMEOUT from e2e_gateway import Gateway, build_gateway +from lifecycle import ResourceManager from e2e_http import ( URL, AuthHeaders, @@ -642,18 +643,24 @@ class LoggingClient: return self.list_langfuse_observations(creds, trace_id=gen.trace_id) or [gen] -def build_logging_client() -> LoggingClient: +def build_logging_client() -> tuple[LoggingClient, ResourceManager]: + """The suite's client plus a session ResourceManager holding the teardown + for the models registered here; the caller runs teardown at session end.""" client = LoggingClient(gateway=build_gateway()) - client.create_model( + resources = ResourceManager(client=client.gateway) + bedrock_sonnet = client.create_model( "bedrock/us.anthropic.claude-sonnet-5", LiteLLMParamsBody(model="bedrock/us.anthropic.claude-sonnet-5"), ) - client.create_model( + resources.defer(lambda: client.delete_model(bedrock_sonnet)) + bedrock_opus = client.create_model( "bedrock/us.anthropic.claude-opus-4-8", LiteLLMParamsBody(model="bedrock/us.anthropic.claude-opus-4-8"), ) - client.create_model( + resources.defer(lambda: client.delete_model(bedrock_opus)) + anthropic_sonnet = client.create_model( "anthropic/claude-sonnet-5", LiteLLMParamsBody(model="anthropic/claude-sonnet-5", api_key="os.environ/ANTHROPIC_API_KEY"), ) - return client + resources.defer(lambda: client.delete_model(anthropic_sonnet)) + return client, resources