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]

Merge branch 'main' into feature/enhance_logging_for_containers

Krish Dholakia900bd1090526
diff --cc .gitignore
index 9613ef77d90,ed8c88c8990..547734ddceb
--- a/.gitignore
+++ b/.gitignore
@@@ -94,4 -95,4 +95,5 @@@ test.p
litellm_config.yaml
.cursor
.vscode/launch.json
- *.whl
-litellm/proxy/to_delete_loadtest_work/*
++*.whl
++litellm/proxy/to_delete_loadtest_work/*
diff --cc tests/test_litellm/conftest.py
index db4224ca6e4,ac8a00d850c..dd0f03a8a37
--- a/tests/test_litellm/conftest.py
+++ b/tests/test_litellm/conftest.py
@@@ -23,68 -9,23 +23,77 @@@ os.environ["LITELLM_LOG_FILE"] = test_l
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
- import litellm
-
-
+ import asyncio
+ import litellm
[email protected](scope="function")
+def temp_log_file():
+ """
+ Creates a temporary log file in /tmp/litellm<random_number>.log for testing.
+ Returns the path to the temporary log file and cleans it up after the test.
+ """
+ # Generate a random number for the log file
+ random_number = ''.join(random.choices(string.digits, k=8))
+ log_file_path = f"/tmp/litellm{random_number}.log"
+
+ # Set the environment variable for litellm to use this temporary log file
+ original_log_file = os.environ.get("LITELLM_LOG_FILE")
+ os.environ["LITELLM_LOG_FILE"] = log_file_path
+
+ yield log_file_path
+
+ # Cleanup: Restore original environment variable and remove the temporary file
+ if original_log_file is not None:
+ os.environ["LITELLM_LOG_FILE"] = original_log_file
+ else:
+ os.environ.pop("LITELLM_LOG_FILE", None)
+
+ # Remove the temporary log file if it exists
+ if os.path.exists(log_file_path):
+ try:
+ os.remove(log_file_path)
+ except OSError:
+ pass # Ignore errors if file can't be removed
+
+
[email protected](scope="session", autouse=True)
+def cleanup_temp_log_dir():
+ """
+ Cleans up the temporary log directory created at module import time.
+ This runs once per test session after all tests are complete.
+ """
+ yield
+
+ if orig_log_file is not None:
+ os.environ["LITELLM_LOG_FILE"] = orig_log_file
+ else:
+ os.environ.pop("LITELLM_LOG_FILE", None)
+
+ # Cleanup: Remove the temporary directory created at module import time
+ if os.path.exists(temp_dir):
+ try:
+ # Remove the test log file first
+ if os.path.exists(test_log_file):
+ os.remove(test_log_file)
+
+ # Remove the temporary directory
+ import shutil
+ shutil.rmtree(temp_dir, ignore_errors=True)
+ except OSError:
+ pass # Ignore errors if cleanup fails
+ @pytest.fixture(scope="session")
+ def event_loop():
+ try:
+ loop = asyncio.get_running_loop()
+ except RuntimeError:
+ loop = asyncio.new_event_loop()
+ yield loop
+ loop.close()
+
+
-
@pytest.fixture(scope="function", autouse=True)
def setup_and_teardown():
"""