@@ -566,26 +566,15 @@ def test_get_table_partition_details_non_partitioned_metastore(self):
566566 self .assertIsNone (partition )
567567
568568 def test_get_table_partition_details_non_partitioned_describe (self ):
569- class ConnectionContextManager :
570- def __init__ (self , connection ):
571- self ._connection = connection
572-
573- def __enter__ (self ):
574- return self ._connection
575-
576- def __exit__ (self , exc_type , exc , tb ):
577- return False
578-
569+ self .hive .engine = types .SimpleNamespace (
570+ url = types .SimpleNamespace (drivername = "hive" )
571+ )
579572 mock_connection = Mock ()
580573 mock_connection .execute .return_value = [
581574 ("id" , "int" , None ),
582575 ("name" , "string" , None ),
583576 ]
584-
585- self .hive .engine = types .SimpleNamespace (
586- url = types .SimpleNamespace (drivername = "hive" ),
587- connect = lambda : ConnectionContextManager (mock_connection ),
588- )
577+ self .hive ._connection_map [self .thread_id ] = mock_connection
589578
590579 is_partitioned , partition = self .hive .get_table_partition_details (
591580 table_name = "non_partitioned" , schema_name = "sample_schema" , inspector = Mock ()
@@ -595,16 +584,9 @@ def __exit__(self, exc_type, exc, tb):
595584 self .assertIsNone (partition )
596585
597586 def test_get_table_partition_details_from_describe_formatted (self ):
598- class ConnectionContextManager :
599- def __init__ (self , connection ):
600- self ._connection = connection
601-
602- def __enter__ (self ):
603- return self ._connection
604-
605- def __exit__ (self , exc_type , exc , tb ):
606- return False
607-
587+ self .hive .engine = types .SimpleNamespace (
588+ url = types .SimpleNamespace (drivername = "hive" )
589+ )
608590 mock_connection = Mock ()
609591 mock_connection .execute .return_value = [
610592 ("id" , "int" , None ),
@@ -616,11 +598,7 @@ def __exit__(self, exc_type, exc, tb):
616598 ("# Detailed Table Information" , None , None ),
617599 ("Database:" , "default" , None ),
618600 ]
619-
620- self .hive .engine = types .SimpleNamespace (
621- url = types .SimpleNamespace (drivername = "hive" ),
622- connect = lambda : ConnectionContextManager (mock_connection ),
623- )
601+ self .hive ._connection_map [self .thread_id ] = mock_connection
624602
625603 is_partitioned , partition = self .hive .get_table_partition_details (
626604 table_name = "sample_table" , schema_name = "sample_schema" , inspector = Mock ()
0 commit comments