mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
Merge pull request #21279 from BerriAI/fix/tokenizer-cache-test-isolation
fix(test): clear tokenizer LRU cache for test isolation
This commit is contained in:
commit
49fd1b5de4
1 changed files with 13 additions and 0 deletions
|
|
@ -491,7 +491,20 @@ from unittest.mock import MagicMock, patch
|
|||
from litellm.utils import _select_tokenizer_helper, claude_json_str, encoding
|
||||
|
||||
|
||||
# Clear the cache at module load to ensure clean state
|
||||
_select_tokenizer_helper.cache_clear()
|
||||
|
||||
|
||||
class TestTokenizerSelection(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Clear the LRU cache before each test method.
|
||||
|
||||
The _select_tokenizer_helper function is decorated with @lru_cache,
|
||||
which can cause cache hits from previous tests when running with
|
||||
--dist=loadscope (tests from same file run on same worker).
|
||||
"""
|
||||
_select_tokenizer_helper.cache_clear()
|
||||
|
||||
@patch("litellm.utils.Tokenizer.from_pretrained")
|
||||
def test_llama3_tokenizer_api_failure(self, mock_from_pretrained):
|
||||
# Setup mock to raise an error
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue