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]

fix(tests): anchor VCR redis cassette key to repo root

Claude6be7b7751399
diff --git a/tests/_vcr_redis_persister.py b/tests/_vcr_redis_persister.py
index 4d72a1142bb..a6ed448f1cb 100644
--- a/tests/_vcr_redis_persister.py
+++ b/tests/_vcr_redis_persister.py
@@ -13,6 +13,8 @@ CASSETTE_REDIS_URL_ENV = "CASSETTE_REDIS_URL"
VCR_VERBOSE_ENV = "LITELLM_VCR_VERBOSE"
MAX_EPISODES_PER_CASSETTE = 50
+_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
_log = logging.getLogger(__name__)
_passed_by_cassette_key: dict[str, bool] = {}
@@ -22,7 +24,11 @@ def mark_test_outcome_for_cassette(cassette_path: str, passed: bool) -> None:
def redis_key_for(cassette_path: str) -> str:
- rel = os.path.relpath(str(cassette_path))
+ abs_path = os.path.abspath(str(cassette_path))
+ try:
+ rel = os.path.relpath(abs_path, start=_REPO_ROOT)
+ except ValueError:
+ rel = os.path.basename(abs_path)
if rel.endswith(".yaml"):
rel = rel[: -len(".yaml")]
rel = rel.replace("/cassettes/", "/").lstrip("./")
diff --git a/tests/llm_translation/test_vcr_redis_persister.py b/tests/llm_translation/test_vcr_redis_persister.py
index 853558150c1..6e62e4491cb 100644
--- a/tests/llm_translation/test_vcr_redis_persister.py
+++ b/tests/llm_translation/test_vcr_redis_persister.py
@@ -81,6 +81,31 @@ def test_redis_key_normalizes_path_passed_by_pytest_recording():
)
+def test_redis_key_is_stable_across_working_directories(tmp_path, monkeypatch):
+ repo_root = os.path.dirname(
+ os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ )
+ abs_cassette = os.path.join(
+ repo_root,
+ "tests/llm_translation/cassettes/test_anthropic/test_streaming.yaml",
+ )
+
+ monkeypatch.chdir(repo_root)
+ key_from_root = redis_key_for(abs_cassette)
+
+ monkeypatch.chdir(os.path.join(repo_root, "tests", "llm_translation"))
+ key_from_subdir = redis_key_for(abs_cassette)
+
+ monkeypatch.chdir(tmp_path)
+ key_from_tmp = redis_key_for(abs_cassette)
+
+ assert key_from_root == key_from_subdir == key_from_tmp
+ assert (
+ key_from_root
+ == "litellm:vcr:cassette:tests/llm_translation/test_anthropic/test_streaming"
+ )
+
+
class _FlakyRedis:
def __init__(self, inner, fail_on: str):
self._inner = inner