mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 12:23:28 +00:00
refactor: simplify cache clearing to avoid over-engineering
Based on Greptile feedback: - Removed autouse fixture (applied too broadly to unrelated tests) - Removed setUpClass (redundant since setUp runs before every test) - Kept module-level clear and setUp() method (sufficient for test isolation) - Added blank line for proper formatting The simplified approach still ensures test isolation under --dist=loadscope while avoiding unnecessary complexity. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
bae8816c35
commit
706792ba96
@@ -495,27 +495,14 @@ from litellm.utils import _select_tokenizer_helper, claude_json_str, encoding
|
||||
_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
|
||||
|
||||
|
||||
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."""
|
||||
"""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")
|
||||
|
||||
Reference in New Issue
Block a user