fix(test): mock environment variables for callback validation test#21286
Merged
fix(test): mock environment variables for callback validation test#21286
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR fixes a test isolation issue in
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| tests/proxy_unit_tests/test_proxy_utils.py | Adds monkeypatch fixture to mock LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY env vars, preventing Pydantic validation errors when running in parallel execution environments. |
Sequence Diagram
sequenceDiagram
participant Test as Test Function
participant MP as monkeypatch
participant PC as ProxyConfig
participant GTC as _get_team_config
participant GS as get_secret()
participant ENV as os.environ
participant TCM as TeamCallbackMetadata
Test->>MP: setenv("LANGFUSE_PUBLIC_KEY", "test_public_key")
Test->>MP: setenv("LANGFUSE_SECRET_KEY", "test_secret_key")
MP->>ENV: Set env vars
Test->>PC: update_config_state(config)
Test->>PC: load_team_config("test")
PC->>GTC: _get_team_config("test", all_teams_config)
GTC->>GS: get_secret("os.environ/LANGFUSE_PUBLIC_KEY")
GS->>ENV: os.environ.get("LANGFUSE_PUBLIC_KEY")
ENV-->>GS: "test_public_key"
GS-->>GTC: "test_public_key"
GTC->>GS: get_secret("os.environ/LANGFUSE_SECRET_KEY")
GS->>ENV: os.environ.get("LANGFUSE_SECRET_KEY")
ENV-->>GS: "test_secret_key"
GS-->>GTC: "test_secret_key"
GTC-->>PC: team_config (with resolved values)
PC-->>Test: team_config
Test->>TCM: TeamCallbackMetadata(callback_vars=...)
Note over TCM: Pydantic validates Dict[str, str] ✓
Last reviewed commit: 2d41b03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
test_proxy_config_state_post_init_callback_callfailure when running with pytest-xdist parallel execution (--dist=loadscope).Problem
The test was failing with Pydantic validation error:
Root cause: The test configures callback settings with environment variable references:
These get resolved at runtime. In parallel execution:
LANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEY) may not be setNoneinstead of a stringSolution
Use
monkeypatchto set the required environment variables before test execution:This ensures:
Testing
pytest tests/proxy_unit_tests/test_proxy_utils.py::test_proxy_config_state_post_init_callback_call -vRelated
🤖 Generated with Claude Code