litellm/tests/local_testing/test_register_model.py
kerry 8ecbf3dbc1 test: drop tests that pin provider-owned cost map values
The repo rule is that a test must only fail when litellm code changes, never when a vendor updates a price, renames a field, or drops a model. These tests asserted shipped catalog entries directly, comparing lookup results to literals copied from model_prices_and_context_window.json or requiring named entries to exist or be absent, so every cost map sync could break them without any litellm code changing

Tests that exercise real litellm behavior with an injected local model_cost, invariants like backup parity, and assertions on non-lookup code paths are untouched

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-18 03:55:51 +00:00

65 lines
2 KiB
Python

#### What this tests ####
# This tests calling batch_completions by running 100 messages together
import ast
from pathlib import Path
import pytest
import litellm
def test_update_model_cost():
try:
litellm.register_model(
{
"gpt-4": {
"max_tokens": 8192,
"input_cost_per_token": 0.00002,
"output_cost_per_token": 0.00006,
"litellm_provider": "openai",
"mode": "chat",
},
}
)
assert litellm.model_cost["gpt-4"]["input_cost_per_token"] == 0.00002
except Exception as e:
pytest.fail(f"An error occurred: {e}")
# test_update_model_cost()
# test_update_model_cost_map_url()
def test_update_model_cost_via_completion():
try:
response = litellm.completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hey, how's it going?"}],
input_cost_per_token=0.3,
output_cost_per_token=0.4,
)
print(f"litellm.model_cost for gpt-3.5-turbo: {litellm.model_cost['gpt-3.5-turbo']}")
assert litellm.model_cost["gpt-3.5-turbo"]["input_cost_per_token"] == 0.3
assert litellm.model_cost["gpt-3.5-turbo"]["output_cost_per_token"] == 0.4
except Exception as e:
pytest.fail(f"An error occurred: {e}")
def test_no_test_invocation_at_module_scope():
tree = ast.parse(Path(__file__).read_text())
defined = {node.name for node in tree.body if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))}
invoked = [
node.value.func.id
for node in tree.body
if isinstance(node, ast.Expr)
and isinstance(node.value, ast.Call)
and isinstance(node.value.func, ast.Name)
and node.value.func.id in defined
]
assert not invoked, (
f"{invoked} run at import time, so pytest collecting this file fires real "
"provider calls; any failure aborts collection and tears down the whole job"
)