mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 16:24:59 +00:00
fix(test): mock environment variables for callback validation test
The test test_proxy_config_state_post_init_callback_call was failing with: ``` ValidationError: 2 validation errors for TeamCallbackMetadata callback_vars.langfuse_public_key Input should be a valid string [type=string_type, input_value=None, input_type=NoneType] ``` Root cause: The test uses environment variable references like "os.environ/LANGFUSE_PUBLIC_KEY" which get resolved at runtime. In parallel execution with --dist=loadscope, these environment variables may not be set in all worker processes, causing the resolution to return None, which fails Pydantic validation expecting strings. Solution: Use monkeypatch to set the required environment variables before the test runs. This ensures consistent behavior across all test execution environments (local, CI, parallel workers). Fixes test failure exposed by PR #21277. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
b0f2b4bb2d
commit
2d41b03f8b
@@ -1170,17 +1170,25 @@ def test_team_callback_metadata_none_values(none_key):
|
||||
assert none_key not in resp
|
||||
|
||||
|
||||
def test_proxy_config_state_post_init_callback_call():
|
||||
def test_proxy_config_state_post_init_callback_call(monkeypatch):
|
||||
"""
|
||||
Ensures team_id is still in config, after callback is called
|
||||
|
||||
Addresses issue: https://github.com/BerriAI/litellm/issues/6787
|
||||
|
||||
Where team_id was being popped from config, after callback was called
|
||||
|
||||
Note: Environment variables are mocked to avoid validation errors
|
||||
in parallel execution where env vars may not be set.
|
||||
"""
|
||||
from litellm.proxy.litellm_pre_call_utils import LiteLLMProxyRequestSetup
|
||||
from litellm.proxy.proxy_server import ProxyConfig
|
||||
|
||||
# Mock environment variables to avoid Pydantic validation errors
|
||||
# when env vars are resolved to None in parallel execution
|
||||
monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "test_public_key")
|
||||
monkeypatch.setenv("LANGFUSE_SECRET_KEY", "test_secret_key")
|
||||
|
||||
pc = ProxyConfig()
|
||||
|
||||
pc.update_config_state(
|
||||
|
||||
Reference in New Issue
Block a user