3535
3636
3737def test_empty_config_file_is_created_if_not_present ():
38+ from snowflake .cli .api .utils .path_utils import path_resolver
39+
40+ from tests .conftest import clean_logging_handlers
41+
3842 with TemporaryDirectory () as tmp_dir :
39- config_file = Path (tmp_dir ) / "sub" / "config.toml"
43+ # Resolve Windows short paths to prevent cleanup issues
44+ resolved_tmp_dir = path_resolver (tmp_dir )
45+ config_file = Path (resolved_tmp_dir ) / "sub" / "config.toml"
4046 assert config_file .exists () is False
4147
42- config_init (config_file )
43- assert config_file .exists () is True
44-
45- assert_file_permissions_are_strict (config_file )
48+ try :
49+ config_init (config_file )
50+ assert config_file .exists () is True
51+ assert_file_permissions_are_strict (config_file )
52+ finally :
53+ # Ensure all logging handlers are closed before temp directory cleanup
54+ clean_logging_handlers ()
4655
4756
4857@mock .patch .dict (os .environ , {}, clear = True )
@@ -161,16 +170,26 @@ def test_get_all_connections(test_snowcli_config):
161170def test_create_default_config_if_not_exists_with_proper_permissions (
162171 mock_get_config_section ,
163172):
173+ from snowflake .cli .api .utils .path_utils import path_resolver
174+
175+ from tests .conftest import clean_logging_handlers
176+
164177 mock_get_config_section .return_value = {}
165178 with TemporaryDirectory () as tmp_dir :
166- config_path = Path (f"{ tmp_dir } /snowflake/config.toml" )
179+ # Resolve Windows short paths to prevent cleanup issues
180+ resolved_tmp_dir = path_resolver (tmp_dir )
181+ config_path = Path (f"{ resolved_tmp_dir } /snowflake/config.toml" )
167182
168- # Test the config initialization with a specific path
169- config_init (config_path )
183+ try :
184+ # Test the config initialization with a specific path
185+ config_init (config_path )
170186
171- assert config_path .exists ()
172- assert_file_permissions_are_strict (config_path .parent )
173- assert_file_permissions_are_strict (config_path )
187+ assert config_path .exists ()
188+ assert_file_permissions_are_strict (config_path .parent )
189+ assert_file_permissions_are_strict (config_path )
190+ finally :
191+ # Ensure all logging handlers are closed before temp directory cleanup
192+ clean_logging_handlers ()
174193
175194
176195@mock .patch .dict (
@@ -496,8 +515,14 @@ def test_too_wide_permissions_on_custom_config_file_causes_warning(
496515def test_too_wide_permissions_on_custom_config_file_causes_warning_windows (permissions ):
497516 import subprocess
498517
518+ from snowflake .cli .api .utils .path_utils import path_resolver
519+
520+ from tests .conftest import clean_logging_handlers
521+
499522 with TemporaryDirectory () as tmp_dir :
500- config_path = Path (tmp_dir ) / "config.toml"
523+ # Resolve Windows short paths to prevent cleanup issues
524+ resolved_tmp_dir = path_resolver (tmp_dir )
525+ config_path = Path (resolved_tmp_dir ) / "config.toml"
501526 config_path .touch ()
502527 result = subprocess .run (
503528 ["icacls" , str (config_path ), "/GRANT" , f"Everyone:{ permissions } " ],
@@ -506,11 +531,15 @@ def test_too_wide_permissions_on_custom_config_file_causes_warning_windows(permi
506531 )
507532 assert result .returncode == 0 , result .stdout + result .stderr
508533
509- with pytest .warns (
510- UserWarning ,
511- match = r"Unauthorized users \(.*\) have access to configuration file .*" ,
512- ):
513- config_init (config_file = config_path )
534+ try :
535+ with pytest .warns (
536+ UserWarning ,
537+ match = r"Unauthorized users \(.*\) have access to configuration file .*" ,
538+ ):
539+ config_init (config_file = config_path )
540+ finally :
541+ # Ensure all logging handlers are closed before temp directory cleanup
542+ clean_logging_handlers ()
514543
515544
516545@parametrize_chmod
0 commit comments