test(lazy_imports): check star-import exports against globals(), not dir() - #39958
Closed
yuneng-berri wants to merge 1 commit into
Closed
test(lazy_imports): check star-import exports against globals(), not dir()#39958yuneng-berri wants to merge 1 commit into
yuneng-berri wants to merge 1 commit into
Conversation
…dir() dir() inside a list comprehension only sees the comprehension's own scope, so every name in litellm.__all__ read as missing and the test could never pass. Star import itself was fine; the check is now against the module globals, and appending a bogus name to __all__ makes it fail as intended.
Contributor
Greptile SummaryThis PR corrects the lazy-import regression test to inspect the module namespace populated by
Confidence Score: 5/5The PR appears safe to merge because the corrected assertion accurately checks the namespace populated by the star import The subprocess uses a fresh module-level namespace, so
|
| Filename | Overview |
|---|---|
| tests/test_litellm/test_lazy_imports.py | Correctly checks star-imported names in the fresh subprocess module namespace |
Reviews (1): Last reviewed commit: "test(lazy_imports): check star-import ex..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
7 tasks
6 tasks
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.
TLDR
Problem this solves:
test_star_import_exports_public_api(added in perf: lazy-load SDK symbols so import litellm stays under 60 MB RSS #39121) fails on every Python versiondir()inside a list comprehension only sees the comprehension's own scopefrom litellm import *, works fineHow it solves it:
globals()instead ofdir()__all__User Flow
Before: a contributor opens any PR against
litellm_internal_stagingand the misc unit-test jobs go red without them touching anything relatedUnit Testsworkflow runsmisc / Run testson Python 3.10, 3.11, 3.13 and 3.14tests/test_litellm/test_lazy_imports.py::test_star_import_exports_public_apiwith an assertion listingAI21ChatConfig,AI21Config, ... as missingAfter: the same PR gets green misc jobs
Unit Testsworkflow runsmisc / Run testson Python 3.10, 3.11, 3.13 and 3.14litellm.__all__stops being importableRelevant issues
Introduced by #39121
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
This is a test-only change with no proxy or LLM behavior involved, so the proof is the check the test runs, executed by hand in a fresh interpreter, plus the test itself with and without a deliberately broken export
Before (bf51dea)
The check as written in the test
python -c 'from litellm import *; import litellm; missing = [n for n in litellm.__all__ if n not in dir()]; print(len(missing), "of", len(litellm.__all__))'1519 of 1519The same check against globals()
python -c 'from litellm import *; import litellm; missing = [n for n in litellm.__all__ if n not in globals()]; print(len(missing), "of", len(litellm.__all__))'0 of 1519, so star import was never brokenThe test
pytest tests/test_litellm/test_lazy_imports.py::test_star_import_exports_public_api -q1 failed,AssertionError: ['AI21ChatConfig', 'AI21Config', 'ALL_RESPONSES_API_TOOL_PARAMS', ...](same as CI on all four Python versions)After (e4296b9)
The check as written in the test
python -c 'from litellm import *; import litellm; missing = [n for n in litellm.__all__ if n not in globals()]; print(len(missing), "of", len(litellm.__all__))'0 of 1519The same check against globals()
globals()0 of 1519The test
pytest tests/test_litellm/test_lazy_imports.py -q22 passed, 1 skippedMutation check: the test catches a broken export
litellm/__init__.pyto__all__ = list(STAR_IMPORT_PUBLIC_NAMES) + ["bogus_not_exported"]pytest tests/test_litellm/test_lazy_imports.py::test_star_import_exports_public_api -q1 failed,AttributeError: module 'litellm' has no attribute 'bogus_not_exported'Type
✅ Test
Caveats (if any)
Final Attestation