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
This commit is contained in:
yuneng-jiang 2026-09-26 20:26:23 -07:00 • committed by GitHub
parent ba2d1c2785
commit 303434d573
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 10 deletions

View file

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

View file

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

View file

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