From 303434d5738b5c1b0bbd226792fb40c1c21b6a16 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Sat, 26 Sep 2026 20:26:23 -0700 Subject: [PATCH] test(e2e): report batch cleanup leftovers as a plain UserWarning (#43405) The leftover warning used a class defined in a test-directory module. The xdist controller cannot import it, so an uncaught leftover warning crashed the whole e2e run. Same change as #43391 on rc/1.103.0 --- tests/e2e/batches/COVERAGE.md | 2 +- tests/e2e/batches/batch_cleanup.py | 8 ++------ tests/e2e/batches/test_batch_cleanup.py | 5 ++--- 3 files changed, 5 insertions(+), 10 deletions(-) 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)