mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-02 02:11:58 +00:00
test: inject fake lakera_ai module to avoid importing the real one
CI fix for the lakera regression test: it stubbed litellm.proxy.proxy_server with a SimpleNamespace and then monkeypatch.setattr'd the real lakera_ai module, which forces importing it — and lakera_ai does `from litellm.proxy.proxy_server import LiteLLM_TeamTable`, absent on the stub -> ImportError under proxy-infra tests. Inject a fake lakera_ai module into sys.modules instead, so the callbacks branch's `from ...lakera_ai import lakeraAI_Moderation` resolves to the stub without loading the real module. The guard under test (isinstance(dict) in the lakera branch) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bab6a8f208
commit
c37b41ad58
1 changed files with 12 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import copy
|
||||
import sys
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
from types import ModuleType, SimpleNamespace
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../../..")
|
||||
|
|
@ -331,15 +331,22 @@ def test_initialize_callbacks_on_proxy_lakera_ignores_non_dict_callback_settings
|
|||
def __init__(self, **kwargs):
|
||||
captured["kwargs"] = kwargs
|
||||
|
||||
# Inject a fake lakera_ai module so the branch's
|
||||
# `from ...lakera_ai import lakeraAI_Moderation` resolves to our stub without
|
||||
# importing the real module (which imports proxy_server symbols not present
|
||||
# under the stubbed proxy_server below).
|
||||
fake_lakera = ModuleType("litellm.proxy.guardrails.guardrail_hooks.lakera_ai")
|
||||
fake_lakera.lakeraAI_Moderation = _DummyLakera
|
||||
monkeypatch.setitem(
|
||||
sys.modules,
|
||||
"litellm.proxy.guardrails.guardrail_hooks.lakera_ai",
|
||||
fake_lakera,
|
||||
)
|
||||
monkeypatch.setitem(
|
||||
sys.modules,
|
||||
"litellm.proxy.proxy_server",
|
||||
SimpleNamespace(prisma_client=None),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"litellm.proxy.guardrails.guardrail_hooks.lakera_ai.lakeraAI_Moderation",
|
||||
_DummyLakera,
|
||||
)
|
||||
|
||||
original_callbacks = (
|
||||
list(litellm.callbacks) if isinstance(litellm.callbacks, list) else []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue