1515import os
1616import pytest
1717import yaml
18+ import logging
1819from mock import Mock , MagicMock
1920
2021from sagemaker .config .config import (
@@ -246,6 +247,7 @@ def test_merge_of_s3_default_config_file_and_regular_config_file(
246247def test_logging_when_overriden_admin_and_user_configs_are_found (get_data_dir , caplog ):
247248 # Should log info message stating defaults were fetched since both exist
248249 logger .propagate = True
250+
249251 os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ] = get_data_dir
250252 os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ] = get_data_dir
251253 load_sagemaker_config ()
@@ -258,12 +260,51 @@ def test_logging_when_overriden_admin_and_user_configs_are_found(get_data_dir, c
258260 "Not applying SDK defaults from location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH )
259261 not in caplog .text
260262 )
263+ del os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ]
264+ del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
265+ logger .propagate = False
266+
267+ def test_logging_when_overriden_admin_is_found_and_default_user_config_not_found (get_data_dir , caplog ):
268+ logger .propagate = True
269+ caplog .set_level (logging .DEBUG , logger = logger .name )
270+ os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ] = get_data_dir
271+ load_sagemaker_config ()
272+ assert "Fetched defaults config from location: {}" .format (get_data_dir ) in caplog .text
273+ assert (
274+ "Not applying SDK defaults from location: {}" .format (
275+ _DEFAULT_USER_CONFIG_FILE_PATH )
276+ in caplog .text
277+ )
278+ assert "Unable to load the config file from the location: {}" .format (
279+ _DEFAULT_USER_CONFIG_FILE_PATH
280+ ) in caplog .text
281+ del os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ]
282+ logger .propagate = False
283+
284+
285+ def test_logging_when_default_admin_not_found_and_overriden_user_config_is_found (get_data_dir , caplog ):
286+ logger .propagate = True
287+ caplog .set_level (logging .DEBUG , logger = logger .name )
288+ os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ] = get_data_dir
289+ load_sagemaker_config ()
290+ assert "Fetched defaults config from location: {}" .format (get_data_dir ) in caplog .text
291+ assert (
292+ "Not applying SDK defaults from location: {}" .format (
293+ _DEFAULT_ADMIN_CONFIG_FILE_PATH )
294+ in caplog .text
295+ )
296+ assert "Unable to load the config file from the location: {}" .format (
297+ _DEFAULT_ADMIN_CONFIG_FILE_PATH
298+ ) in caplog .text
299+ del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
300+ logger .propagate = False
261301
262302
263- def test_logging_when_default_admin_and_user_config_not_found (caplog ):
303+ def test_logging_when_default_admin_and_default_user_config_not_found (caplog ):
264304 # Should log info message stating sdk defaults were not applied
265305 # for admin and user config since both are missing from default location
266306 logger .propagate = True
307+ caplog .set_level (logging .DEBUG , logger = logger .name )
267308 load_sagemaker_config ()
268309 assert (
269310 "Not applying SDK defaults from location: {}" .format (_DEFAULT_ADMIN_CONFIG_FILE_PATH )
@@ -273,6 +314,9 @@ def test_logging_when_default_admin_and_user_config_not_found(caplog):
273314 "Not applying SDK defaults from location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH )
274315 in caplog .text
275316 )
317+ assert "Unable to load the config file from the location: {}" .format (_DEFAULT_ADMIN_CONFIG_FILE_PATH ) in caplog .text
318+ assert "Unable to load the config file from the location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH ) in caplog .text
319+ logger .propagate = False
276320
277321
278322def test_logging_when_default_admin_and_overriden_user_config_not_found (get_data_dir , caplog ):
@@ -292,6 +336,7 @@ def test_logging_when_default_admin_and_overriden_user_config_not_found(get_data
292336 not in caplog .text
293337 )
294338 del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
339+ logger .propagate = False
295340
296341
297342def test_logging_when_overriden_admin_and_overridden_user_config_not_found (get_data_dir , caplog ):
@@ -313,6 +358,7 @@ def test_logging_when_overriden_admin_and_overridden_user_config_not_found(get_d
313358 )
314359 del os .environ ["SAGEMAKER_USER_CONFIG_OVERRIDE" ]
315360 del os .environ ["SAGEMAKER_ADMIN_CONFIG_OVERRIDE" ]
361+ logger .propagate = False
316362
317363
318364def test_logging_with_additional_configs_and_none_are_found (caplog ):
@@ -330,3 +376,4 @@ def test_logging_with_additional_configs_and_none_are_found(caplog):
330376 "Not applying SDK defaults from location: {}" .format (_DEFAULT_USER_CONFIG_FILE_PATH )
331377 in caplog .text
332378 )
379+ logger .propagate = False
0 commit comments