Repository navigation
test(client): clear the endpoint variables around the lifecycle tests - #243
Draft
jeffdupont wants to merge 3 commits into
Draft
jeffdupont wants to merge 3 commits into
jeffdupont wants to merge 3 commits into
Conversation
Two TestInitClientSDKKeyPath tests assert the exact Config call, and init_client passes LD_BASE_URI, LD_STREAM_URI and LD_EVENTS_URI to it. Importing litellm during collection runs load_dotenv(), which walks up from the working directory, so a checkout with a .env setting those variables failed both tests locally while CI passed. An autouse fixture now clears all three, matching clear_endpoint_env in test_skills_fdv2.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_dotenv() searches upward from the calling file, litellm's own install directory, not from the working directory. That is why a .venv inside a checkout finds that checkout's .env. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Two tests in
packages/client/tests/test_lifecycle.pyfail locally when the whole suite runs, and pass on their own and in CI:TestInitClientSDKKeyPath::test_uses_options_sdk_key_over_env_varTestInitClientSDKKeyPath::test_retries_after_a_failed_init_instead_of_replaying_itBoth assert the exact
Config(...)call, and got stagingbase_uri/stream_uri/events_urikeyword arguments they did not expect.Cause
litellm/__init__.pycallsload_dotenv()on import whenLITELLM_MODEisDEV, its default. pytest imports the litellm package tests during collection, before any test runs.find_dotenvsearches upward from the calling file, which is litellm's own install directory, so a.venvinside a checkout finds that checkout's.env. A.envthat setsLD_BASE_URI,LD_STREAM_URIorLD_EVENTS_URItherefore puts them inos.environfor the rest of the run.Neither failing test clears those variables.
test_retries_after_a_failed_init_instead_of_replaying_itcopiesos.environminus onlyLD_SDK_KEY, andtest_uses_options_sdk_key_over_env_varpatchesos.environwithout clearing it.init_clientpasses all three variables toConfig.CI has no
.env, so it never sees this.Checked by importing each provider SDK in a clean process: only
litellmsetsLD_BASE_URI.Fix
An autouse
clear_endpoint_envfixture intest_lifecycle.pydeletes the three variables around each test withmonkeypatch, the same wayclear_endpoint_envintest_skills_fdv2.pyalready does for its two.Verification
.envsetting the three variables: 2 failed before,3714 passed, 18 skippedafter (on the currentmain).make lint format-check: clean.Not in this PR
litellmloading a.envon import also affects customers oflaunchdarkly-ai-litellm-*, not only tests: a project whose virtualenv sits inside it loads that project's.env, whatever the working directory. The SDK itself never loads one (test_never_loads_a_dotenv_file), but the dependency does. That is a separate question.🤖 Generated with Claude Code