@@ -31,7 +31,13 @@ class TestConfiguration(unittest.TestCase):
3131 env_vars = dict (os .environ )
3232
3333 def setUp (self ):
34- """Set up test fixtures."""
34+ # Save current environment variables
35+ self .saved_env = dict (os .environ )
36+
37+ def tearDown (self ):
38+ # Restore environment variables
39+ os .environ .clear ()
40+ os .environ .update (self .saved_env )
3541
3642 def env_path (self , filename ):
3743 """Return the path to the .env file."""
@@ -40,7 +46,7 @@ def env_path(self, filename):
4046 def test_conf_defaults (self ):
4147 """Test that settings == SettingsDefaults when no .env is in use."""
4248 os .environ .clear ()
43- mock_settings = Settings ()
49+ mock_settings = Settings (init_info = "test_conf_defaults()" )
4450 os .environ .update (self .env_vars )
4551
4652 self .assertEqual (mock_settings .aws_region , SettingsDefaults .AWS_REGION )
@@ -70,7 +76,7 @@ def test_env_illegal_nulls(self):
7076 self .assertTrue (loaded )
7177
7278 with self .assertRaises (PydanticValidationError ):
73- Settings ()
79+ Settings (init_info = "test_env_illegal_nulls()" )
7480
7581 os .environ .update (self .env_vars )
7682
@@ -81,7 +87,7 @@ def test_env_nulls(self):
8187 loaded = load_dotenv (env_path )
8288 self .assertTrue (loaded )
8389
84- mock_settings = Settings ()
90+ mock_settings = Settings (init_info = "test_env_nulls()" )
8591 os .environ .update (self .env_vars )
8692
8793 self .assertEqual (mock_settings .aws_region , SettingsDefaults .AWS_REGION )
@@ -103,7 +109,7 @@ def test_env_overrides(self):
103109 loaded = load_dotenv (env_path )
104110 self .assertTrue (loaded )
105111
106- mock_settings = Settings ()
112+ mock_settings = Settings (init_info = "test_env_overrides()" )
107113 os .environ .update (self .env_vars )
108114
109115 self .assertEqual (mock_settings .aws_region , "us-west-1" )
@@ -122,7 +128,7 @@ def test_env_overrides(self):
122128 def test_aws_credentials_with_profile (self ):
123129 """Test that key and secret are unset when using profile."""
124130
125- mock_settings = Settings ()
131+ mock_settings = Settings (init_info = "test_aws_credentials_with_profile()" )
126132 self .assertEqual (mock_settings .aws_access_key_id_source , "aws_profile" )
127133 self .assertEqual (mock_settings .aws_secret_access_key_source , "aws_profile" )
128134
@@ -132,7 +138,7 @@ def test_aws_credentials_with_profile(self):
132138 def test_aws_credentials_without_profile (self ):
133139 """Test that key and secret are set by environment variable when provided."""
134140
135- mock_settings = Settings ()
141+ mock_settings = Settings (init_info = "test_aws_credentials_without_profile()" )
136142 # pylint: disable=no-member
137143 self .assertEqual (mock_settings .aws_access_key_id .get_secret_value (), "TEST_KEY" )
138144 # pylint: disable=no-member
@@ -148,7 +154,7 @@ def test_aws_credentials_without_profile(self):
148154 def test_aws_credentials_noinfo (self ):
149155 """Test that key and secret remain unset when no profile nor environment variables are provided."""
150156 os .environ .clear ()
151- mock_settings = Settings ()
157+ mock_settings = Settings (init_info = "test_aws_credentials_noinfo()" )
152158 os .environ .update (self .env_vars )
153159 aws_profile = TFVARS .get ("aws_profile" , None )
154160 self .assertEqual (mock_settings .aws_profile , aws_profile )
@@ -169,21 +175,21 @@ def test_invalid_aws_region_code(self):
169175 """Test that Pydantic raises a validation error for environment variable with non-existent aws region code."""
170176
171177 with self .assertRaises (RekognitionValueError ):
172- Settings ()
178+ Settings (init_info = "test_invalid_aws_region_code()" )
173179
174180 @patch .dict (os .environ , {"AWS_REKOGNITION_FACE_DETECT_MAX_FACES_COUNT" : "-1" })
175181 def test_invalid_max_faces_count (self ):
176182 """Test that Pydantic raises a validation error for environment variable w negative integer values."""
177183
178184 with self .assertRaises (PydanticValidationError ):
179- Settings ()
185+ Settings (init_info = "test_invalid_max_faces_count()" )
180186
181187 @patch .dict (os .environ , {"AWS_REKOGNITION_FACE_DETECT_THRESHOLD" : "-1" })
182188 def test_invalid_threshold (self ):
183189 """Test that Pydantic raises a validation error for environment variable w negative integer values."""
184190
185191 with self .assertRaises (PydanticValidationError ):
186- Settings ()
192+ Settings (init_info = "test_invalid_threshold()" )
187193
188194 def test_configure_with_class_constructor (self ):
189195 """test that we can set values with the class constructor"""
@@ -197,6 +203,7 @@ def test_configure_with_class_constructor(self):
197203 aws_rekognition_face_detect_quality_filter = "TEST_AUTO" ,
198204 aws_rekognition_face_detect_threshold = 102 ,
199205 debug_mode = True ,
206+ init_info = "test_configure_with_class_constructor()" ,
200207 )
201208
202209 self .assertEqual (mock_settings .aws_region , "eu-west-1" )
@@ -212,15 +219,20 @@ def test_configure_neg_int_with_class_constructor(self):
212219 """test that we cannot set negative int values with the class constructor"""
213220
214221 with self .assertRaises (PydanticValidationError ):
215- Settings (aws_rekognition_face_detect_max_faces_count = - 1 )
222+ Settings (
223+ aws_rekognition_face_detect_max_faces_count = - 1 ,
224+ init_info = "test_configure_neg_int_with_class_constructor()" ,
225+ )
216226
217227 with self .assertRaises (PydanticValidationError ):
218- Settings (aws_rekognition_face_detect_threshold = - 1 )
228+ Settings (
229+ aws_rekognition_face_detect_threshold = - 1 , init_info = "test_configure_neg_int_with_class_constructor()"
230+ )
219231
220232 def test_readonly_settings (self ):
221233 """test that we can't set readonly values with the class constructor"""
222234
223- mock_settings = Settings (aws_region = "eu-west-1" )
235+ mock_settings = Settings (aws_region = "eu-west-1" , init_info = "test_readonly_settings()" )
224236 with self .assertRaises (PydanticValidationError ):
225237 mock_settings .aws_region = "us-west-1"
226238
0 commit comments