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
This commit is contained in:
mubashir1osmani 2026-07-13 18:37:54 -07:00
parent 996ae432c5
commit c428ada090
2 changed files with 19 additions and 8 deletions

View file

@ -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

View file

@ -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