@@ -30,8 +30,9 @@ def test_client_initialization_region_mismatch():
3030 """Test client initialization with region mismatch warning."""
3131
3232 with patch ("boto3.client" ) as mock_boto_client :
33+ # First test - environment variable takes precedence
3334 with patch ("boto3.Session" ) as mock_session :
34- # Mock the session instance
35+ # Mock the session instance to simulate AWS_REGION=us-east-1
3536 mock_session_instance = MagicMock ()
3637 mock_session_instance .region_name = "us-east-1"
3738 mock_session .return_value = mock_session_instance
@@ -41,17 +42,23 @@ def test_client_initialization_region_mismatch():
4142 mock_client_instance .meta .region_name = "us-east-1"
4243 mock_boto_client .return_value = mock_client_instance
4344
44- # When region_name is not provided, it should use the boto3 default
45- client1 = MemoryClient ()
46- assert client1 .region_name == "us-east-1"
45+ # When region_name is provided, environment variable should still take precedence
46+ client1 = MemoryClient (region_name = "us-west-2" )
47+ assert client1 .region_name == "us-east-1" # Environment wins over explicit param
4748
48- # Reset the mock to test with a specified region
49- mock_boto_client .reset_mock ()
49+ # Second test - no environment variable, explicit param is used
50+ with patch ("boto3.Session" ) as mock_session :
51+ # Mock the session instance to simulate no AWS_REGION set
52+ mock_session_instance = MagicMock ()
53+ mock_session_instance .region_name = None
54+ mock_session .return_value = mock_session_instance
55+
56+ # Mock the boto client
5057 mock_client_instance = MagicMock ()
5158 mock_client_instance .meta .region_name = "us-west-2"
5259 mock_boto_client .return_value = mock_client_instance
5360
54- # When region_name is provided, it should use that value
61+ # When AWS_REGION is not set, explicitly provided region should be used
5562 client2 = MemoryClient (region_name = "us-west-2" )
5663 assert client2 .region_name == "us-west-2"
5764
0 commit comments