mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix(tests): isolate litellm.cache and CLI env vars in flaky tests
- TestSpendLogsPayload: save/restore litellm.cache in setup_method/teardown_method so tests that run after a cache-setting test don't see a non-None cache and get a hash instead of "Cache OFF" in the cache_key field - test_use_prisma_db_push_flag_behavior: apply clean_env pattern (strip DATABASE_URL/DIRECT_URL, then set DATABASE_URL to test value) inside the with block instead of using @patch.dict decorator, matching the pattern from test_skip_server_startup to avoid Click 8.3.x StreamMixer stream lifecycle issues in CI
This commit is contained in:
parent
b17d37eceb
commit
17da1ab01d
2 changed files with 15 additions and 3 deletions
|
|
@ -1231,9 +1231,12 @@ async def _wait_for_mock_call(mock, timeout=10, interval=0.1):
|
|||
class TestSpendLogsPayload:
|
||||
def setup_method(self):
|
||||
self._original_callbacks = litellm.callbacks[:]
|
||||
self._original_cache = litellm.cache
|
||||
litellm.cache = None
|
||||
|
||||
def teardown_method(self):
|
||||
litellm.callbacks = self._original_callbacks
|
||||
litellm.cache = self._original_cache
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_spend_logs_payload_e2e(self):
|
||||
|
|
|
|||
|
|
@ -586,9 +586,6 @@ class TestHealthAppFactory:
|
|||
@patch("litellm.proxy.db.prisma_client.PrismaManager.setup_database")
|
||||
@patch("litellm.proxy.db.check_migration.check_prisma_schema_diff")
|
||||
@patch("litellm.proxy.db.prisma_client.should_update_prisma_schema")
|
||||
@patch.dict(
|
||||
os.environ, {"DATABASE_URL": "postgresql://test:test@localhost:5432/test"}
|
||||
)
|
||||
def test_use_prisma_db_push_flag_behavior(
|
||||
self,
|
||||
mock_should_update_schema,
|
||||
|
|
@ -616,7 +613,19 @@ class TestHealthAppFactory:
|
|||
save_worker_config=MagicMock(),
|
||||
)
|
||||
|
||||
# Strip DIRECT_URL and set DATABASE_URL to a test value so Click's
|
||||
# CliRunner doesn't encounter real DB env vars (causes stream lifecycle
|
||||
# issues with Click 8.3.x in CI environments).
|
||||
clean_env = {
|
||||
k: v
|
||||
for k, v in os.environ.items()
|
||||
if k not in ("DATABASE_URL", "DIRECT_URL")
|
||||
}
|
||||
clean_env["DATABASE_URL"] = "postgresql://test:test@localhost:5432/test"
|
||||
|
||||
with patch.dict(
|
||||
os.environ, clean_env, clear=True
|
||||
), patch.dict(
|
||||
"sys.modules",
|
||||
{
|
||||
"proxy_server": mock_proxy_module,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue