This commit is contained in:
cursor[bot] 2026-09-14 18:46:47 -04:00 committed by GitHub
commit 40e85c5b20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,52 @@ import pytest
# stub the prisma SDK do so per-test via monkeypatch, which is properly scoped.
_MANAGED_DB_ENV_VARS = (
"IAM_TOKEN_DB_AUTH",
"DATABASE_URL",
"DATABASE_URL_READ_REPLICA",
"DATABASE_HOST",
"DATABASE_PORT",
"DATABASE_USER",
"DATABASE_USERNAME",
"DATABASE_NAME",
"DATABASE_SCHEMA",
"DATABASE_PASSWORD",
"DATABASE_HOST_READ_REPLICA",
"DATABASE_PORT_READ_REPLICA",
"DATABASE_USER_READ_REPLICA",
"DATABASE_USERNAME_READ_REPLICA",
"DATABASE_NAME_READ_REPLICA",
"DATABASE_SCHEMA_READ_REPLICA",
"DATABASE_PASSWORD_READ_REPLICA",
)
@pytest.fixture(autouse=True)
def _scrub_db_env():
"""Snapshot and restore DB env vars across every test in this module.
`PrismaWrapper.get_rds_iam_token` (and a few sibling code paths) write
`DATABASE_URL` directly into `os.environ`, which `monkeypatch` cannot
undo when the variable started out unset. Without this fixture the
synthesized writer URL leaks into later tests in the same xdist worker;
e.g. `tests/test_litellm/proxy/common_utils/test_key_rotation_e2e.py::
TestDeprecatedKeyLookupDbE2E::test_deprecated_key_grace_period_cache_hit_path`
stops skipping (`os.getenv("DATABASE_URL")` is now truthy) and tries to
open a Prisma connection against the bogus host, failing with
`httpx.ConnectError`. Mirrors the fixture in `test_db_url_settings.py`.
"""
saved = {var: os.environ.get(var) for var in _MANAGED_DB_ENV_VARS}
try:
yield
finally:
for var, value in saved.items():
if value is None:
os.environ.pop(var, None)
else:
os.environ[var] = value
def _make_wrappers():
from litellm.proxy.db.prisma_client import PrismaWrapper