Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): report batch cleanup leftovers as a plain UserWarning (#43405)

yuneng-jiang303434d5738b
diff --git a/tests/e2e/batches/COVERAGE.md b/tests/e2e/batches/COVERAGE.md
index cd0fb35165e..2ba49a492ff 100644
--- a/tests/e2e/batches/COVERAGE.md
+++ b/tests/e2e/batches/COVERAGE.md
@@ -134,7 +134,7 @@ reporting failures as test errors. Already deleted files and batches that are
terminal are safe to clean up again. Managed batch cancellation polls for up to two minutes
before input deletion. A managed batch still `cancelling` after that is left for the provider to
finish, and its input file is left in place because LiteLLM refuses to delete a file a non-terminal
-batch references. Both are reported as `BatchCleanupLeftover` warnings naming their ids rather than
+batch references. Both are reported as `UserWarning`s naming their ids rather than
failing the test. Any other status or error still fails
Accepted cancellation may still report validating or in_progress while the provider
updates its state. Raw and model-encoded batches are polled until cancelling or
diff --git a/tests/e2e/batches/batch_cleanup.py b/tests/e2e/batches/batch_cleanup.py
index 5b3baaa624c..f1142a60782 100644
--- a/tests/e2e/batches/batch_cleanup.py
+++ b/tests/e2e/batches/batch_cleanup.py
@@ -28,10 +28,6 @@ class BatchCleanupClient(Protocol):
def cancel_batch(self, batch_id: str, *, key: str, provider: str | None = None) -> Result[BatchObject]: ...
-class BatchCleanupLeftover(UserWarning):
- pass
-
-
def cleanup_result[R: BaseModel](
action: Callable[[], Result[R]], *, wait: Callable[[float], None] = sleep
) -> Result[R]:
@@ -68,7 +64,7 @@ def cleanup_file(client: BatchCleanupClient, file_id: str, *, key: str, provider
if isinstance(result, UnknownApiError) and result.status_code == 400 and FILE_IN_USE_REFUSAL in result.body:
warnings.warn(
f"Left file {file_id} in place: LiteLLM refused to delete it while a batch still references it",
- BatchCleanupLeftover,
+ UserWarning,
stacklevel=2,
)
return
@@ -140,7 +136,7 @@ def cleanup_batch(
)
warnings.warn(
f"Left batch {batch_id} cancelling after {BATCH_CANCEL_TIMEOUT_SECONDS}s for the provider to finish",
- BatchCleanupLeftover,
+ UserWarning,
stacklevel=2,
)
return
diff --git a/tests/e2e/batches/test_batch_cleanup.py b/tests/e2e/batches/test_batch_cleanup.py
index 5e2ac12d300..218e79f37ac 100644
--- a/tests/e2e/batches/test_batch_cleanup.py
+++ b/tests/e2e/batches/test_batch_cleanup.py
@@ -7,7 +7,6 @@ import pytest
from batch_cleanup import (
BATCH_CANCEL_TIMEOUT_SECONDS,
CLEANUP_DELAYS,
- BatchCleanupLeftover,
cleanup_batch,
cleanup_file,
cleanup_result,
@@ -141,7 +140,7 @@ class TestFileCleanup:
calls=ExpectedCalls((f"delete None {MANAGED_FILE_ID}",)),
files=(UnknownApiError(status_code=400, body=IN_USE_REFUSAL),),
)
- with pytest.warns(BatchCleanupLeftover, match=MANAGED_FILE_ID):
+ with pytest.warns(UserWarning, match=MANAGED_FILE_ID):
cleanup_file(client, MANAGED_FILE_ID, key="test-key")
client.calls.assert_done()
@@ -241,7 +240,7 @@ class TestBatchCancellation:
key: Final = manager.key()
manager.defer(lambda: cleanup_file(client, MANAGED_FILE_ID, key=key))
manager.defer(lambda: cleanup_batch(client, MANAGED_BATCH_ID, key=key, clock=ticks))
- with pytest.warns(BatchCleanupLeftover) as leftovers:
+ with pytest.warns(UserWarning, match="^Left ") as leftovers:
manager.teardown()
client.calls.assert_done()
messages: Final = tuple(str(warning.message) for warning in leftovers)