@@ -3108,18 +3108,17 @@ def test_urllib() -> str:
31083108)
31093109def test_use_default_artifact_repository (db_parameters ):
31103110 with Session .builder .configs (db_parameters ).create () as session :
3111+ temp_database = Utils .random_temp_database ()
31113112 temp_schema = Utils .random_temp_schema ()
3112- session .sql (f"create schema { temp_schema } " ).collect ()
3113- session .sql (f"use schema { temp_schema } " ).collect ()
3113+ session .sql (f"create database { temp_database } " ).collect ()
3114+ session .sql (f"use database { temp_database } " ).collect ()
31143115 session .sql (
31153116 "ALTER SESSION SET ENABLE_DEFAULT_PYTHON_ARTIFACT_REPOSITORY = true"
31163117 ).collect ()
31173118 session .sql (
3118- "ALTER schema set DEFAULT_PYTHON_ARTIFACT_REPOSITORY = testdb_snowpark_python.testschema_snowpark_python.SNOWPARK_PYTHON_TEST_REPOSITORY "
3119+ "ALTER database set DEFAULT_PYTHON_ARTIFACT_REPOSITORY = snowflake.snowpark.anaconda_shared_repository "
31193120 ).collect ()
31203121
3121- session .add_packages ("art" , "cloudpickle" )
3122-
31233122 def test_art () -> str :
31243123 import art # art is not available in the conda channel, but is in pypi
31253124
@@ -3128,6 +3127,25 @@ def test_art() -> str:
31283127
31293128 temp_func_name = Utils .random_name_for_temp_object (TempObjectType .FUNCTION )
31303129
3130+ # should not work in the database where the default is anaconda
3131+ with pytest .raises (
3132+ Exception ,
3133+ match = "Cannot add package art because it is not available in Snowflake" ,
3134+ ):
3135+ udf (
3136+ session = session ,
3137+ func = test_art ,
3138+ name = temp_func_name ,
3139+ packages = ["art" , "cloudpickle" ],
3140+ )
3141+
3142+ session .sql (f"create schema { temp_schema } " ).collect ()
3143+ session .use_schema (temp_schema )
3144+ session .sql (
3145+ "ALTER schema set DEFAULT_PYTHON_ARTIFACT_REPOSITORY = testdb_snowpark_python.testschema_snowpark_python.SNOWPARK_PYTHON_TEST_REPOSITORY"
3146+ ).collect ()
3147+ session .add_packages ("art" , "cloudpickle" )
3148+
31313149 try :
31323150 # Test function registration
31333151 udf (
@@ -3142,4 +3160,4 @@ def test_art() -> str:
31423160 finally :
31433161 session ._run_query (f"drop function if exists { temp_func_name } (int)" )
31443162
3145- session .sql (f"drop schema { temp_schema } " ).collect ()
3163+ session .sql (f"drop database { temp_database } " ).collect ()
0 commit comments