Files
litellm/tests/_flush_vcr_cache.py
T
mateo-berri e1f2b4b818 tests(vcr): trim non-load-bearing comments and docstrings
Removes commentary that restated the code, including:

- module-level banners explaining what the conftest does (covered by
  Readme.md and the function bodies)
- docstrings on _scrub_response, _before_record_response, vcr_config,
  _vcr_disabled, pytest_recording_configure (function names + bodies
  are self-evident)
- inline notes about header filtering, match_on, etc.
- per-test docstrings restating the test name

Keeps the two non-obvious notes that aren't recoverable from the code:
the vcrpy/respx httpx-transport collision rationale on
_RESPX_CONFLICTING_FILES, the vcrpy "return None to skip persisting"
contract on filter_non_2xx_response, and the fixture-ordering
dependency on _vcr_record_retries.
2026-04-30 21:48:48 +00:00

45 lines
1.1 KiB
Python

from __future__ import annotations
import os
import sys
import redis
PREFIX = "litellm:vcr:cassette:"
SCAN_BATCH = 500
def _client() -> redis.Redis:
host = os.environ.get("REDIS_HOST")
if not host:
sys.exit("REDIS_HOST is not set; cannot flush VCR cache")
return redis.Redis(
host=host,
port=int(os.environ.get("REDIS_PORT", 6379)),
password=os.environ.get("REDIS_PASSWORD") or None,
socket_timeout=5,
socket_connect_timeout=5,
decode_responses=False,
)
def main() -> None:
client = _client()
deleted = 0
pipeline = client.pipeline(transaction=False)
pending = 0
for key in client.scan_iter(match=f"{PREFIX}*", count=SCAN_BATCH):
pipeline.delete(key)
pending += 1
if pending >= SCAN_BATCH:
deleted += sum(pipeline.execute())
pipeline = client.pipeline(transaction=False)
pending = 0
if pending:
deleted += sum(pipeline.execute())
print(f"Deleted {deleted} VCR cassette key(s) under {PREFIX!r}")
if __name__ == "__main__":
main()