Skip to content

Commit 7f432ff

Browse files
tests(llm): use pytest monkeypatch for env vars in ssl_verify parsing test
Replaces direct os.environ manipulation with monkeypatch.setenv so env is auto-restored and the test is isolated. Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 8ee3d30 commit 7f432ff

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

tests/sdk/llm/test_llm.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from typing import Any
32
from unittest.mock import Mock, patch
43

@@ -540,32 +539,31 @@ def test_llm_responses_ssl_verify_and_custom_provider(mock_responses):
540539
assert kwargs.get("api_base") == "https://corporate-proxy.example.com/api"
541540

542541

543-
def test_llm_ssl_verify_env_parsing():
544-
"""Test that ssl_verify is correctly parsed from environment variables."""
542+
def test_llm_ssl_verify_env_parsing(monkeypatch):
543+
"""Test that ssl_verify is correctly parsed from environment variables.
544+
545+
Use pytest's monkeypatch to ensure environment is restored automatically.
546+
"""
547+
# Ensure model is set for all subsequent load_from_env calls
548+
monkeypatch.setenv("LLM_MODEL", "gpt-4")
549+
545550
# Test various false values
546551
for value in ["false", "False", "FALSE", "0", "no", "off"]:
547-
os.environ["LLM_SSL_VERIFY"] = value
548-
os.environ["LLM_MODEL"] = "gpt-4"
552+
monkeypatch.setenv("LLM_SSL_VERIFY", value)
549553
llm = LLM.load_from_env()
550554
assert llm.ssl_verify is False, f"Failed for value: {value}"
551555

552556
# Test various true values
553557
for value in ["true", "True", "TRUE", "1", "yes", "on"]:
554-
os.environ["LLM_SSL_VERIFY"] = value
558+
monkeypatch.setenv("LLM_SSL_VERIFY", value)
555559
llm = LLM.load_from_env()
556560
assert llm.ssl_verify is True, f"Failed for value: {value}"
557561

558562
# Test certificate path (string value)
559-
os.environ["LLM_SSL_VERIFY"] = "/path/to/cert.pem"
563+
monkeypatch.setenv("LLM_SSL_VERIFY", "/path/to/cert.pem")
560564
llm = LLM.load_from_env()
561565
assert llm.ssl_verify == "/path/to/cert.pem"
562566

563-
# Clean up
564-
if "LLM_SSL_VERIFY" in os.environ:
565-
del os.environ["LLM_SSL_VERIFY"]
566-
if "LLM_MODEL" in os.environ:
567-
del os.environ["LLM_MODEL"]
568-
569567

570568
def test_llm_vision_support(default_llm):
571569
"""Test LLM vision support detection."""

0 commit comments

Comments
 (0)