Merge pull request #21423 from BerriAI/fix/token-counter-test-isolation

fix(token-counter): fix test isolation and encode() return type normalization
This commit is contained in:
jquinter 2026-02-17 21:22:05 -03:00 • committed by GitHub
commit 59171bd76d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -582,14 +582,15 @@ class TestTokenizerSelection(unittest.TestCase):
@patch("litellm.utils._return_huggingface_tokenizer")
def test_disable_hf_tokenizer_download(self, mock_return_huggingface_tokenizer):
# Use pytest.MonkeyPatch() directly instead of fixture
monkeypatch = pytest.MonkeyPatch()
monkeypatch.setattr(litellm, "disable_hf_tokenizer_download", True)
result = _select_tokenizer_helper("grok-32r22r")
mock_return_huggingface_tokenizer.assert_not_called()
assert result["type"] == "openai_tokenizer"
assert result["tokenizer"] == encoding
try:
result = _select_tokenizer_helper("grok-32r22r")
mock_return_huggingface_tokenizer.assert_not_called()
assert result["type"] == "openai_tokenizer"
assert result["tokenizer"] == encoding
finally:
monkeypatch.undo()
@pytest.mark.parametrize(