Files
litellm/tests/local_testing/test_multiple_deployments.py
T
Mateo Wang c1602587c1 fix(tests): drop module-level test calls that break local_testing collection (#29520)
* fix(tests): drop module-level test calls that break local_testing collection

Several files in tests/local_testing invoked their test functions at module
scope (e.g. test_register_model.py ran test_update_model_cost_via_completion()
at the bottom of the file). Those calls execute during pytest collection, so
they fire real network requests at import time. test_register_model.py's call
hit an OpenAI 429 and raised, turning into a collection error.

A collection error aborts the whole session for every job that globs
tests/local_testing/**/test_*.py, which is why unrelated jobs like
langfuse_logging_unit_tests (-k langfuse) and litellm_assistants_api_testing
(-k assistants) both failed even though neither touches register_model;
the -k filter only applies after collection.

pytest discovers and runs these test_* functions on its own, so the top-level
calls were dead and harmful. Removes them from test_register_model.py,
test_wandb.py, test_lunary.py, and test_multiple_deployments.py, and adds a
regression test that scans the directory for module-level test invocations.

* test(local_testing): skip unparseable files in module-scope invocation guardrail

A syntax error in any tests/local_testing file would make ast.parse raise an
unhandled SyntaxError, so the guardrail itself would crash with a confusing
traceback instead of its assertion message. Such a file already fails pytest
collection on its own, which is the clearer signal, so the guardrail now skips
files it cannot parse and stays focused on detecting module-scope test calls.
Reads files as utf-8 for deterministic behavior across platforms.
2026-06-02 13:07:05 -07:00

52 lines
1.6 KiB
Python

#### What this tests ####
# This tests error handling + logging (esp. for sentry breadcrumbs)
import sys, os
import traceback
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import pytest
import litellm
from litellm import completion
messages = [{"role": "user", "content": "Hey, how's it going?"}]
## All your mistral deployments ##
model_list = [
{
"model_name": "mistral-7b-instruct",
"litellm_params": { # params for litellm completion/embedding call
"model": "replicate/mistralai/mistral-7b-instruct-v0.1:83b6a56e7c828e667f21fd596c338fd4f0039b46bcfa18d973e8e70e455fda70",
"api_key": os.getenv("REPLICATE_API_KEY"),
},
},
{
"model_name": "mistral-7b-instruct",
"litellm_params": { # params for litellm completion/embedding call
"model": "together_ai/Qwen/Qwen2.5-7B-Instruct-Turbo",
"api_key": os.getenv("TOGETHERAI_API_KEY"),
},
},
{
"model_name": "mistral-7b-instruct",
"litellm_params": {
"model": "deepinfra/mistralai/Mistral-7B-Instruct-v0.1",
"api_key": os.getenv("DEEPINFRA_API_KEY"),
},
},
]
def test_multiple_deployments():
try:
## LiteLLM completion call ## returns first response
response = completion(
model="mistral-7b-instruct", messages=messages, model_list=model_list
)
print(f"response: {response}")
except Exception as e:
traceback.print_exc()
pytest.fail(f"An exception occurred: {e}")