From 11b4d76b19c9761accff96e0c7e7350d7600a89d Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Sat, 21 Feb 2026 14:37:33 -0800 Subject: [PATCH] fix(tests): use monkeypatch.setenv for Redis pool max_connections tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace patch('litellm._redis._get_redis_client_logic') with monkeypatch.setenv in test_max_connections_url_config and test_max_connections_url_config_string_value. The mock was unreliable in CI (REDIS_URL is set to the real Redis Cloud server), causing the pool to silently use the real config instead of the test config. Using monkeypatch.setenv tests the full env-var→pool chain more robustly and matches the actual production code path. --- .../caching/test_redis_connection_pool.py | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/test_litellm/caching/test_redis_connection_pool.py b/tests/test_litellm/caching/test_redis_connection_pool.py index 69381653ac0..b8922846e82 100644 --- a/tests/test_litellm/caching/test_redis_connection_pool.py +++ b/tests/test_litellm/caching/test_redis_connection_pool.py @@ -39,29 +39,25 @@ def test_url_config_falls_back_to_from_url_without_pool(): assert client.connection_pool is not None -def test_max_connections_url_config(): +def test_max_connections_url_config(monkeypatch): """max_connections should be respected when using URL-based config.""" - with patch("litellm._redis._get_redis_client_logic") as mock_logic: - mock_logic.return_value = { - "url": "redis://localhost:6379/0", - "max_connections": 10, - } + monkeypatch.setenv("REDIS_URL", "redis://localhost:6379/0") + monkeypatch.delenv("REDIS_HOST", raising=False) + monkeypatch.setenv("REDIS_MAX_CONNECTIONS", "10") - pool = get_redis_connection_pool() + pool = get_redis_connection_pool() assert pool.max_connections == 10 -def test_max_connections_url_config_string_value(): +def test_max_connections_url_config_string_value(monkeypatch): """max_connections provided as a string (from env var) should be cast to int.""" - with patch("litellm._redis._get_redis_client_logic") as mock_logic: - mock_logic.return_value = { - "url": "redis://localhost:6379/0", - "max_connections": "25", - } + monkeypatch.setenv("REDIS_URL", "redis://localhost:6379/0") + monkeypatch.delenv("REDIS_HOST", raising=False) + monkeypatch.setenv("REDIS_MAX_CONNECTIONS", "25") - pool = get_redis_connection_pool() + pool = get_redis_connection_pool() assert pool.max_connections == 25