Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/test_litellm/litellm_core_utils/test_token_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,32 @@ def test_token_counter():
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()


@pytest.fixture(autouse=True, scope="function")
def clear_tokenizer_cache_before_test():
"""Clear the LRU cache before each test to ensure test isolation.

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).
"""
# Clear before test
_select_tokenizer_helper.cache_clear()
yield
Comment thread
jquinter marked this conversation as resolved.
Outdated


class TestTokenizerSelection(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Clear cache before class starts."""
_select_tokenizer_helper.cache_clear()

def setUp(self):
"""Clear cache before each test method."""
_select_tokenizer_helper.cache_clear()
@patch("litellm.utils.Tokenizer.from_pretrained")
Comment thread
jquinter marked this conversation as resolved.
def test_llama3_tokenizer_api_failure(self, mock_from_pretrained):
# Setup mock to raise an error
Expand Down
Loading