@@ -183,11 +183,10 @@ def redshift_external_schema(cloudformation_outputs, databases_parameters, glue_
183183 IAM_ROLE '{ databases_parameters ["redshift" ]["role" ]} '
184184 REGION '{ region } ';
185185 """
186- con = wr .redshift .connect (connection = "aws-sdk-pandas-redshift" )
187- with con .cursor () as cursor :
188- cursor .execute (sql )
189- con .commit ()
190- con .close ()
186+ with wr .redshift .connect (connection = "aws-sdk-pandas-redshift" ) as con :
187+ with con .cursor () as cursor :
188+ cursor .execute (sql )
189+ con .commit ()
191190 return "aws_sdk_pandas_external"
192191
193192
@@ -284,23 +283,21 @@ def redshift_table():
284283 name = f"tbl_{ get_time_str_with_random_suffix ()} "
285284 print (f"Table name: { name } " )
286285 yield name
287- con = wr .redshift .connect ("aws-sdk-pandas-redshift" )
288- with con .cursor () as cursor :
289- cursor .execute (f"DROP TABLE IF EXISTS public.{ name } " )
290- con .commit ()
291- con .close ()
286+ with wr .redshift .connect ("aws-sdk-pandas-redshift" ) as con :
287+ with con .cursor () as cursor :
288+ cursor .execute (f"DROP TABLE IF EXISTS public.{ name } " )
289+ con .commit ()
292290
293291
294292@pytest .fixture (scope = "function" )
295293def redshift_table_with_hyphenated_name ():
296294 name = f"tbl-{ get_time_str_with_random_suffix ()} "
297295 print (f"Table name: { name } " )
298296 yield name
299- con = wr .redshift .connect ("aws-sdk-pandas-redshift" )
300- with con .cursor () as cursor :
301- cursor .execute (f'DROP TABLE IF EXISTS public."{ name } "' )
302- con .commit ()
303- con .close ()
297+ with wr .redshift .connect ("aws-sdk-pandas-redshift" ) as con :
298+ with con .cursor () as cursor :
299+ cursor .execute (f'DROP TABLE IF EXISTS public."{ name } "' )
300+ con .commit ()
304301
305302
306303@pytest .fixture (scope = "function" )
@@ -405,9 +402,8 @@ def random_glue_database():
405402
406403@pytest .fixture (scope = "function" )
407404def redshift_con ():
408- con = wr .redshift .connect ("aws-sdk-pandas-redshift" )
409- yield con
410- con .close ()
405+ with wr .redshift .connect ("aws-sdk-pandas-redshift" ) as con :
406+ yield con
411407
412408
413409@pytest .fixture (scope = "function" )
0 commit comments