Files
litellm/tests
Alexsander Hamir 1e89aa3068 Fix: Resolve flakiness in three integration tests (#17594)
Fixed three flaky tests that were intermittently failing in CI:

1. test_no_duplicate_spend_logs (test_litellm/responses/test_no_duplicate_spend_logs.py)
   Problem: Used await asyncio.sleep(1) to wait for async logging completion,
            which created race conditions. The async logging worker queues tasks
            in the background, and sleep() doesn't guarantee completion.

   Fix: Replaced sleep() with GLOBAL_LOGGING_WORKER.flush() which properly waits
        for the logging queue to empty, ensuring all async logging tasks complete
        before assertions run.

2. test_log_langfuse_v2_handles_null_usage_values (test_litellm/integrations/test_langfuse.py)
   Problem: Used datetime.datetime.now() twice for start_time and end_time, which
            could cause timing inconsistencies between test runs, especially in
            CI environments with variable execution speeds.

   Fix: Use fixed timestamps instead of datetime.now() to ensure consistent timing
        across all test runs, eliminating timing-related flakiness.

3. test_watsonx_gpt_oss_prompt_transformation (test_litellm/llms/watsonx/test_watsonx.py)
   Problem: Directly accessed mock_post.call_args without checking if it exists,
            which could be None if the mock wasn't called or if an exception
            occurred before the POST request. The test catches exceptions and
            continues, making this a potential failure point.

   Fix: Added proper assertions and use call_args_list[0] for safer access:
        - Assert that call_args_list has at least one call
        - Assert that call_args is not None
        - Assert that 'data' key exists in kwargs
        This ensures the test fails with clear error messages rather than
        intermittent AttributeError exceptions.

All fixes maintain the original test intent while making them deterministic
and reliable in CI environments.
2025-12-06 07:57:03 -08:00
..
2025-12-03 19:43:29 -08:00
fix
2025-11-26 17:11:33 -08:00
2025-12-05 17:12:01 -08:00
2025-12-05 12:40:58 -08:00
2025-12-05 17:12:01 -08:00
2025-11-15 10:34:24 -08:00

In total litellm runs 1000+ tests

[02/20/2025] Update:

To make it easier to contribute and map what behavior is tested,

we've started mapping the litellm directory in tests/test_litellm

This folder can only run mock tests.