Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(tests): drop module-level test calls that break local_testing collection (#29520)

Mateo Wangc1602587c1da
diff --git a/tests/local_testing/test_lunary.py b/tests/local_testing/test_lunary.py
index d181d24c782..0dbae1b817f 100644
--- a/tests/local_testing/test_lunary.py
+++ b/tests/local_testing/test_lunary.py
@@ -26,9 +26,6 @@ def test_lunary_logging():
print(e)
-test_lunary_logging()
-
-
def test_lunary_template():
import lunary
diff --git a/tests/local_testing/test_multiple_deployments.py b/tests/local_testing/test_multiple_deployments.py
index f7276d4f14e..72bfd5012c1 100644
--- a/tests/local_testing/test_multiple_deployments.py
+++ b/tests/local_testing/test_multiple_deployments.py
@@ -49,6 +49,3 @@ def test_multiple_deployments():
except Exception as e:
traceback.print_exc()
pytest.fail(f"An exception occurred: {e}")
-
-
-test_multiple_deployments()
diff --git a/tests/local_testing/test_no_top_level_test_invocations.py b/tests/local_testing/test_no_top_level_test_invocations.py
new file mode 100644
index 00000000000..eb1d836a18d
--- /dev/null
+++ b/tests/local_testing/test_no_top_level_test_invocations.py
@@ -0,0 +1,36 @@
+import ast
+from pathlib import Path
+
+LOCAL_TESTING_DIR = Path(__file__).parent
+
+
+def _top_level_test_invocations(tree):
+ invocations = []
+ for node in tree.body:
+ if not isinstance(node, ast.Expr) or not isinstance(node.value, ast.Call):
+ continue
+ func = node.value.func
+ name = getattr(func, "id", None) or getattr(func, "attr", None)
+ if name and name.startswith("test_"):
+ invocations.append((name, node.lineno))
+ return invocations
+
+
+def test_no_module_level_test_invocations():
+ offenders = []
+ for path in sorted(LOCAL_TESTING_DIR.rglob("*.py")):
+ try:
+ tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
+ except SyntaxError:
+ continue
+ for name, lineno in _top_level_test_invocations(tree):
+ offenders.append(
+ f"{path.relative_to(LOCAL_TESTING_DIR)}:{lineno} calls {name}()"
+ )
+
+ assert not offenders, (
+ "Test functions are invoked at module scope, so they run during pytest "
+ "collection (making network calls and erroring collection for every job "
+ "that globs this directory). Remove these calls; pytest collects test "
+ "functions automatically:\n" + "\n".join(offenders)
+ )
diff --git a/tests/local_testing/test_register_model.py b/tests/local_testing/test_register_model.py
index 6b170798874..635fd79abff 100644
--- a/tests/local_testing/test_register_model.py
+++ b/tests/local_testing/test_register_model.py
@@ -60,6 +60,3 @@ def test_update_model_cost_via_completion():
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}")
-
-
-test_update_model_cost_via_completion()
diff --git a/tests/local_testing/test_wandb.py b/tests/local_testing/test_wandb.py
index 6cdca40492f..58a9c9f5ddf 100644
--- a/tests/local_testing/test_wandb.py
+++ b/tests/local_testing/test_wandb.py
@@ -51,9 +51,6 @@ def test_wandb_logging_async():
pass
-test_wandb_logging_async()
-
-
def test_wandb_logging():
try:
response = completion(