@@ -196,7 +196,16 @@ def test_get_parameters_noname_default(monkeypatch: MonkeyPatch):
196196 "connections" : {"prod" : {"account" : "example-prod-acct" , "role" : "DEVELOPER" }},
197197 }
198198
199- monkeypatch .setattr ("rsconnect.snowflake.CONFIG_MANAGER" , mock_config_manager )
199+ # Mock the import inside get_parameters
200+ def mock_import (name , * args , ** kwargs ):
201+ if name == "snowflake.connector.config_manager" :
202+ # Create a mock module with CONFIG_MANAGER
203+ mock_module = type ("mock_module" , (), {})
204+ mock_module .CONFIG_MANAGER = mock_config_manager
205+ return mock_module
206+ return original_import (name , * args , ** kwargs )
207+
208+ monkeypatch .setattr ("builtins.__import__" , mock_import )
200209
201210 params = get_parameters ()
202211
@@ -209,7 +218,16 @@ def test_get_parameters_named(monkeypatch: MonkeyPatch):
209218
210219 mock_config_manager = {"connections" : {"dev" : {"account" : "example-dev-acct" , "role" : "ACCOUNTADMIN" }}}
211220
212- monkeypatch .setattr ("rsconnect.snowflake.CONFIG_MANAGER" , mock_config_manager )
221+ # Mock the import inside get_parameters
222+ def mock_import (name , * args , ** kwargs ):
223+ if name == "snowflake.connector.config_manager" :
224+ # Create a mock module with CONFIG_MANAGER
225+ mock_module = type ("mock_module" , (), {})
226+ mock_module .CONFIG_MANAGER = mock_config_manager
227+ return mock_module
228+ return original_import (name , * args , ** kwargs )
229+
230+ monkeypatch .setattr ("builtins.__import__" , mock_import )
213231
214232 params = get_parameters ("dev" )
215233
@@ -224,15 +242,34 @@ def test_get_parameters_errs_if_none(monkeypatch: MonkeyPatch):
224242 # Test with invalid default connection
225243 mock_config_manager = {"default_connection_name" : "non_existent" , "connections" : {}}
226244
227- monkeypatch .setattr ("rsconnect.snowflake.CONFIG_MANAGER" , mock_config_manager )
245+ # Mock the import inside get_parameters
246+ def mock_import (name , * args , ** kwargs ):
247+ if name == "snowflake.connector.config_manager" :
248+ # Create a mock module with CONFIG_MANAGER
249+ mock_module = type ("mock_module" , (), {})
250+ mock_module .CONFIG_MANAGER = mock_config_manager
251+ return mock_module
252+ return original_import (name , * args , ** kwargs )
253+
254+ monkeypatch .setattr ("builtins.__import__" , mock_import )
228255
229256 with pytest .raises (RSConnectException ) as excinfo :
230257 get_parameters ()
231258 assert "Could not get Snowflake connection" in str (excinfo .value )
232259
233260 # Test with connections but non-existent name
234261 mock_config_manager = {"connections" : {"prod" : {"account" : "example-prod-acct" }}}
235- monkeypatch .setattr ("rsconnect.snowflake.CONFIG_MANAGER" , mock_config_manager )
262+
263+ # Update the mock with new config
264+ def mock_import (name , * args , ** kwargs ):
265+ if name == "snowflake.connector.config_manager" :
266+ # Create a mock module with CONFIG_MANAGER
267+ mock_module = type ("mock_module" , (), {})
268+ mock_module .CONFIG_MANAGER = mock_config_manager
269+ return mock_module
270+ return original_import (name , * args , ** kwargs )
271+
272+ monkeypatch .setattr ("builtins.__import__" , mock_import )
236273
237274 with pytest .raises (RSConnectException ) as excinfo :
238275 get_parameters ("nexiste" )
0 commit comments