mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
Merge pull request #27025 from BerriAI/litellm_fix-redis-key-generation-d88e
Fix Redis key generation to be stable across working directories
This commit is contained in:
commit
12c9a477f1
2 changed files with 32 additions and 1 deletions
|
|
@ -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("./")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue