Move large text to conftest fixture
Move large text to conftest fixture
Fixes import issues when running unit tests by making a test asset a fixture in the root conftest.py
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
- [X] I have Added testing in the
tests/litellm/directory, Adding at least 1 test is a hard requirement - see details - [X] I have added a screenshot of my new test passing locally
- [X] My PR passes all unit tests on
make test-unit - [X] My PR's scope is as isolated as possible, it only solves 1 specific problem
Type
🐛 Bug Fix 🧹 Refactoring
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| litellm | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 8, 2025 3:24pm |
This sounds like it solves the same problem as #10606 and maybe it’s even nicer in that it puts it in conftest.py so there is no need for imports. I haven’t tested this as I’m on my phone but I like the idea.
Tested this and it works great! @krrishdholakia and @ishaan-jaff: do you think this could be merged? I haven't been able to run make test-unit successfully in a while and this fixes it.
I would love to see this merged. I’m not sure why this doesn’t seem to be an issue for CI or the core devs but there seem to be at least two of us experiencing it.
Please merge this. Without it:
abramowi at Marcs-MacBook-Pro-3 in ~/Code/OpenSource/litellm (main●)
$ poetry run pytest tests/litellm -x -vv
============================= test session starts ==============================
platform darwin -- Python 3.12.9, pytest-7.4.4, pluggy-1.5.0 -- /Users/abramowi/Code/OpenSource/litellm/.venv/bin/python
cachedir: .pytest_cache
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, cov-6.1.1, requests-mock-1.12.1
asyncio: mode=Mode.STRICT
collected 147 items / 1 error
==================================== 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:
.venv/lib/python3.12/site-packages/_pytest/python.py:617: in _importtestmodule
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.venv/lib/python3.12/site-packages/_pytest/pathlib.py:567: in import_path
importlib.import_module(module_name)
/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)
<frozen importlib._bootstrap>:1387: in _gcd_import
???
<frozen importlib._bootstrap>:1360: in _find_and_load
???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:935: in _load_unlocked
???
.venv/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
exec(co, module.__dict__)
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
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 3 warnings, 1 error in 0.66s =========================
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Intrigued why we didn't want to merge this, nevertheless, no point keeping it open still