-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
More robust import of tests.large_text
module
#10606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More robust import of tests.large_text
module
#10606
Conversation
Maybe this is just something in my environment; maybe not. When trying to run `make test-unit` today, I kept getting this: ``` (.venv) abramowi at Marcs-MBP-3 in ~/Code/OpenSource/litellm (main●●) $ make test-unit poetry run pytest tests/litellm/ ============================================================= test session starts ============================================================= platform darwin -- Python 3.12.9, pytest-7.4.4, pluggy-1.5.0 rootdir: /Users/abramowi/Code/OpenSource/litellm plugins: respx-0.22.0, postgresql-7.0.1, anyio-4.5.2, asyncio-0.21.2, mock-3.14.0, requests-mock-1.12.1 asyncio: mode=Mode.STRICT collected 662 items / 2 errors =================================================================== ERRORS ==================================================================== ___________________________________ ERROR collecting tests/litellm/litellm_core_utils/test_token_counter.py ___________________________________ ImportError while importing test module '/Users/abramowi/Code/OpenSource/litellm/tests/litellm/litellm_core_utils/test_token_counter.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py:90: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/litellm/litellm_core_utils/test_token_counter.py:26: in <module> from tests.large_text import text E ModuleNotFoundError: No module named 'tests.large_text' ________________________________ ERROR collecting tests/litellm/litellm_core_utils/test_token_counter_tool.py _________________________________ ImportError while importing test module '/Users/abramowi/Code/OpenSource/litellm/tests/litellm/litellm_core_utils/test_token_counter_tool.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py:90: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/litellm/litellm_core_utils/test_token_counter_tool.py:13: in <module> from test_token_counter import token_counter tests/litellm/litellm_core_utils/test_token_counter.py:26: in <module> from tests.large_text import text E ModuleNotFoundError: No module named 'tests.large_text' ============================================================== warnings summary =============================================================== tests/litellm/integrations/test_custom_prompt_management.py:27 /Users/abramowi/Code/OpenSource/litellm/tests/litellm/integrations/test_custom_prompt_management.py:27: PytestCollectionWarning: cannot collect test class 'TestCustomPromptManagement' because it has a __init__ constructor (from: tests/litellm/integrations/test_custom_prompt_management.py) class TestCustomPromptManagement(CustomPromptManagement): tests/litellm/integrations/arize/test_arize_utils.py:181 /Users/abramowi/Code/OpenSource/litellm/tests/litellm/integrations/arize/test_arize_utils.py:181: PytestCollectionWarning: cannot collect test class 'TestArizeLogger' because it has a __init__ constructor (from: tests/litellm/integrations/arize/test_arize_utils.py) class TestArizeLogger(CustomLogger): tests/litellm/litellm_core_utils/test_streaming_handler.py:505 /Users/abramowi/Code/OpenSource/litellm/tests/litellm/litellm_core_utils/test_streaming_handler.py:505: PytestUnknownMarkWarning: Unknown pytest.mark.flaky - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html @pytest.mark.flaky(reruns=3) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================================================== short test summary info =========================================================== ERROR tests/litellm/litellm_core_utils/test_token_counter.py ERROR tests/litellm/litellm_core_utils/test_token_counter_tool.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ======================================================== 3 warnings, 2 errors in 1.75s ======================================================== make: *** [test-unit] Error 2 ``` I think it's because the existing `sys.path.insert` hack depends on what directory the user is in (it depends on the user's current directory when running `pytest`; it's not related to the location of the test file, though I often make that mistake myself). I changed it to actually make the path relative to the current file, which should be more robust than having it depend on the user's current directory.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I guess you guys still have reservations about #10484? I ask because not only does that improve the speed of pytest runs, but it makes the output less noisier. Notice how in the output below, the filename
![]() Here's another example of the repeating filenames:
![]() |
tests.large_text
module
Closing in favor of #10662 which fixes this in a nicer way using |
Maybe this is just something in my environment; maybe not. When trying to run
make test-unit
today, I kept getting an error:E.g.:
I think it's because the existing
sys.path.insert
hack depends on what directory the user is in (it depends on the user's current directory when runningpytest
; it's not related to the location of the test file, though I often make that mistake myself).For example if I'm in
~/Code/OpenSource/litellm
when I runmake test-unit
thenos.path.abspath("../../..")
evaluates to'/Users/abramowi'
.I changed it to actually make the path relative to the current file, which should be more robust than having it depend on the user's current directory.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
I have Added testing in the
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsI have added a screenshot of my new test passing locally
My PR passes all unit tests on
make test-unit
My PR's scope is as isolated as possible, it only solves 1 specific problem
Type
🐛 Bug Fix
✅ Test
Changes