From 76aa13cde06f7204c84645014bd7657870edb0df Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Thu, 20 Aug 2026 10:30:48 -0700 Subject: [PATCH] test: remove the five test functions a later definition shadows (#37591) Python binds a name once per scope, so when a module or class defines the same test twice only the last one exists. The earlier definitions are unreachable: pytest never collects them, and nothing that references them can fail. A sweep in August cleared nine of these. Five have appeared since, which is the argument for a rule rather than another sweep. Each survivor is the better version, so nothing is lost. The two SQS logger twins additionally stub `asyncio.create_task`, which the shadowed copies did not. The cost-calculator duplicate is a two-line stub that also takes a `model_item` parameter no fixture supplies, so it could not have run even unshadowed. The two `test_prompt_caching` bodies are both `pass`. Collecting the four files reports 416 tests before and after. `tests/proxy_unit_tests/conftest copy.py` goes with them. pytest only loads a file named exactly `conftest.py`, nothing imports this one, and the space in the name says what it was. --- .../test_bedrock_completion.py | 17 ------ tests/llm_translation/test_openai.py | 6 -- tests/local_testing/test_completion_cost.py | 5 -- .../logging_callback_tests/test_sqs_logger.py | 24 -------- tests/proxy_unit_tests/conftest copy.py | 60 ------------------- 5 files changed, 112 deletions(-) delete mode 100644 tests/proxy_unit_tests/conftest copy.py diff --git a/tests/llm_translation/test_bedrock_completion.py b/tests/llm_translation/test_bedrock_completion.py index c6d02930f8b..8dcae7cc997 100644 --- a/tests/llm_translation/test_bedrock_completion.py +++ b/tests/llm_translation/test_bedrock_completion.py @@ -1195,23 +1195,6 @@ def test_not_found_error(): ) -@pytest.mark.parametrize( - "model", - [ - "bedrock/us.anthropic.claude-3-haiku-20240307-v1:0", - "bedrock/us.meta.llama3-2-11b-instruct-v1:0", - ], -) -def test_bedrock_cross_region_inference(model): - litellm.set_verbose = True - response = completion( - model=model, - messages=messages, - max_tokens=10, - temperature=0.1, - ) - - @pytest.mark.parametrize( "model, expected_base_model", [ diff --git a/tests/llm_translation/test_openai.py b/tests/llm_translation/test_openai.py index 22acffd535f..1a14b00c7d7 100644 --- a/tests/llm_translation/test_openai.py +++ b/tests/llm_translation/test_openai.py @@ -285,12 +285,6 @@ class TestOpenAIChatCompletion(BaseLLMChatTest): """Test that tool calls with no arguments is translated correctly. Relevant issue: https://github.com/BerriAI/litellm/issues/6833""" pass - def test_prompt_caching(self): - """ - Test that prompt caching works correctly. - Skip for now, as it's working locally but not in CI - """ - pass def test_prompt_caching(self): """ diff --git a/tests/local_testing/test_completion_cost.py b/tests/local_testing/test_completion_cost.py index cf0c645615d..551b3f064bb 100644 --- a/tests/local_testing/test_completion_cost.py +++ b/tests/local_testing/test_completion_cost.py @@ -2762,11 +2762,6 @@ def model_item(): } -@pytest.mark.parametrize("base_model_arg", ["litellm_param", "model_info"]) -def test_cost_calculator_with_base_model_with_router(base_model_arg, model_item): - from litellm import Router - - @pytest.mark.parametrize("base_model_arg", ["litellm_param", "model_info"]) def test_cost_calculator_with_base_model_with_router(base_model_arg): from litellm import Router diff --git a/tests/logging_callback_tests/test_sqs_logger.py b/tests/logging_callback_tests/test_sqs_logger.py index f141ef14b25..31e9ffc5517 100644 --- a/tests/logging_callback_tests/test_sqs_logger.py +++ b/tests/logging_callback_tests/test_sqs_logger.py @@ -150,30 +150,6 @@ async def test_async_sqs_logger_error_flush(): # ============================================================================= -@pytest.mark.asyncio -async def test_async_log_success_event_adds_to_queue(monkeypatch): - monkeypatch.setattr("litellm.aws_sqs_callback_params", {}) - logger = SQSLogger(sqs_queue_url="https://example.com", sqs_region_name="us-west-2") - - fake_payload = {"some": "data"} - await logger.async_log_success_event( - {"standard_logging_object": fake_payload}, None, None, None - ) - assert fake_payload in logger.log_queue - - -@pytest.mark.asyncio -async def test_async_log_failure_event_adds_to_queue(monkeypatch): - monkeypatch.setattr("litellm.aws_sqs_callback_params", {}) - logger = SQSLogger(sqs_queue_url="https://example.com", sqs_region_name="us-west-2") - - fake_payload = {"fail": True} - await logger.async_log_failure_event( - {"standard_logging_object": fake_payload}, None, None, None - ) - assert fake_payload in logger.log_queue - - # ============================================================================= # 🧾 async_send_batch Tests # ============================================================================= diff --git a/tests/proxy_unit_tests/conftest copy.py b/tests/proxy_unit_tests/conftest copy.py deleted file mode 100644 index 1421700c9a8..00000000000 --- a/tests/proxy_unit_tests/conftest copy.py +++ /dev/null @@ -1,60 +0,0 @@ -# conftest.py - -import importlib -import os -import sys - -import pytest - -sys.path.insert( - 0, os.path.abspath("../..") -) # Adds the parent directory to the system path -import litellm - - -@pytest.fixture(scope="function", autouse=True) -def setup_and_teardown(): - """ - This fixture reloads litellm before every function. To speed up testing by removing callbacks being chained. - """ - curr_dir = os.getcwd() # Get the current working directory - sys.path.insert( - 0, os.path.abspath("../..") - ) # Adds the project directory to the system path - - import litellm - from litellm import Router - - importlib.reload(litellm) - try: - if hasattr(litellm, "proxy") and hasattr(litellm.proxy, "proxy_server"): - importlib.reload(litellm.proxy.proxy_server) - except Exception as e: - print(f"Error reloading litellm.proxy.proxy_server: {e}") - - import asyncio - - loop = asyncio.get_event_loop_policy().new_event_loop() - asyncio.set_event_loop(loop) - print(litellm) - # from litellm import Router, completion, aembedding, acompletion, embedding - yield - - # Teardown code (executes after the yield point) - loop.close() # Close the loop created earlier - asyncio.set_event_loop(None) # Remove the reference to the loop - - -def pytest_collection_modifyitems(config, items): - # Separate tests in 'test_amazing_proxy_custom_logger.py' and other tests - custom_logger_tests = [ - item for item in items if "custom_logger" in item.parent.name - ] - other_tests = [item for item in items if "custom_logger" not in item.parent.name] - - # Sort tests based on their names - custom_logger_tests.sort(key=lambda x: x.name) - other_tests.sort(key=lambda x: x.name) - - # Reorder the items list - items[:] = custom_logger_tests + other_tests