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]

tests(vcr): drop YAML/cassettes-directory metaphor from Redis keys

mateo-berri468b8490728f
diff --git a/tests/_vcr_redis_persister.py b/tests/_vcr_redis_persister.py
index 32cf5c1c0e7..6cbaff84413 100644
--- a/tests/_vcr_redis_persister.py
+++ b/tests/_vcr_redis_persister.py
@@ -11,7 +11,11 @@ REDIS_KEY_PREFIX = "litellm:vcr:cassette:"
def redis_key_for(cassette_path: str) -> str:
- return f"{REDIS_KEY_PREFIX}{os.path.relpath(str(cassette_path))}"
+ rel = os.path.relpath(str(cassette_path))
+ if rel.endswith(".yaml"):
+ rel = rel[: -len(".yaml")]
+ rel = rel.replace("/cassettes/", "/").lstrip("./")
+ return f"{REDIS_KEY_PREFIX}{rel}"
def _redis_url_from_env() -> Optional[str]:
diff --git a/tests/llm_translation/Readme.md b/tests/llm_translation/Readme.md
index e684c73202f..958adbd9755 100644
--- a/tests/llm_translation/Readme.md
+++ b/tests/llm_translation/Readme.md
@@ -7,7 +7,7 @@ Name of the test file is the name of the LLM provider - e.g. `test_openai.py` is
Every test in this directory is auto-decorated with `@pytest.mark.vcr` (via
`conftest.py`). The first time a test runs we hit the live provider and
record the HTTP exchange into Redis under
-`litellm:vcr:cassette:<rel_path>`. Every subsequent run within 24h replays
+`litellm:vcr:cassette:<test_id>`. Every subsequent run within 24h replays
from Redis without touching the network. The 24h TTL means each new day's
first run records again, so upstream API drift surfaces within a day.
diff --git a/tests/llm_translation/test_vcr_redis_persister.py b/tests/llm_translation/test_vcr_redis_persister.py
index 6de6283e6b2..d10aa388c4b 100644
--- a/tests/llm_translation/test_vcr_redis_persister.py
+++ b/tests/llm_translation/test_vcr_redis_persister.py
@@ -41,10 +41,10 @@ def _persister_with_fake_redis():
def test_save_then_load_roundtrips_cassette_content():
_, persister = _persister_with_fake_redis()
- cassette_path = "tests/llm_translation/cassettes/test_x/test_y.yaml"
+ cassette_id = "tests/llm_translation/test_x/test_y"
- persister.save_cassette(cassette_path, _sample_cassette_dict(), yamlserializer)
- requests, responses = persister.load_cassette(cassette_path, yamlserializer)
+ persister.save_cassette(cassette_id, _sample_cassette_dict(), yamlserializer)
+ requests, responses = persister.load_cassette(cassette_id, yamlserializer)
assert len(requests) == 1
assert len(responses) == 1
@@ -56,18 +56,30 @@ def test_save_then_load_roundtrips_cassette_content():
def test_saved_key_has_24h_ttl():
fake, persister = _persister_with_fake_redis()
- cassette_path = "tests/llm_translation/cassettes/test_x/test_ttl.yaml"
+ cassette_id = "tests/llm_translation/test_x/test_ttl"
- persister.save_cassette(cassette_path, _sample_cassette_dict(), yamlserializer)
+ persister.save_cassette(cassette_id, _sample_cassette_dict(), yamlserializer)
- ttl = fake.ttl(redis_key_for(cassette_path))
+ ttl = fake.ttl(redis_key_for(cassette_id))
assert CASSETTE_TTL_SECONDS - 5 <= ttl <= CASSETTE_TTL_SECONDS
def test_load_missing_key_raises_cassette_not_found():
_, persister = _persister_with_fake_redis()
with pytest.raises(CassetteNotFoundError):
- persister.load_cassette("never/recorded.yaml", yamlserializer)
+ persister.load_cassette("never/recorded", yamlserializer)
+
+
+def test_redis_key_normalizes_path_passed_by_pytest_recording():
+ # pytest-recording passes paths shaped like
+ # ``<test_dir>/cassettes/<module>/<test>.yaml``. The persister stores them
+ # under a clean test-identifier key — no extension, no ``cassettes/``
+ # directory segment — so ``redis-cli keys`` reads as test IDs.
+ raw = "tests/llm_translation/cassettes/test_anthropic/test_streaming.yaml"
+ assert (
+ redis_key_for(raw)
+ == "litellm:vcr:cassette:tests/llm_translation/test_anthropic/test_streaming"
+ )
@pytest.mark.parametrize(