From 234a4b69080aac4836269bedf134e2f6dcccf60d Mon Sep 17 00:00:00 2001 From: togear Date: Mon, 7 Sep 2026 19:39:30 +0800 Subject: [PATCH] tests(zai): use monkeypatch.setattr for litellm.api_key to satisfy test-quality rules --- .../zai/test_zai_responses_transformation.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/test_litellm/llms/zai/test_zai_responses_transformation.py b/tests/test_litellm/llms/zai/test_zai_responses_transformation.py index c5f369d2110..40f69a77943 100644 --- a/tests/test_litellm/llms/zai/test_zai_responses_transformation.py +++ b/tests/test_litellm/llms/zai/test_zai_responses_transformation.py @@ -83,17 +83,14 @@ def test_zai_responses_headers_fall_back_to_environment_key(monkeypatch): def test_zai_responses_headers_prefer_zai_key_over_global_key(monkeypatch): monkeypatch.setenv("ZAI_API_KEY", "sk-zai-env") - original_api_key = litellm.api_key - litellm.api_key = "sk-global-other-provider" - try: - config = ZAIResponsesAPIConfig() + monkeypatch.setattr(litellm, "api_key", "sk-global-other-provider", raising=False) - headers = config.validate_environment( - headers={}, - model="glm-5.3", - litellm_params=GenericLiteLLMParams(), - ) - finally: - litellm.api_key = original_api_key + config = ZAIResponsesAPIConfig() + + headers = config.validate_environment( + headers={}, + model="glm-5.3", + litellm_params=GenericLiteLLMParams(), + ) assert headers["Authorization"] == "Bearer sk-zai-env"