@@ -23,6 +23,7 @@ class Testing(unittest.TestCase):
2323
2424 _data = None
2525 _dsn = None
26+ _pyodbc = None
2627
2728 def __init__ (self , test_data , dsn = None ):
2829 super ().__init__ ()
@@ -32,9 +33,10 @@ def __init__(self, test_data, dsn=None):
3233
3334 # only import pyODBC if running tests (vs. for instance only loading test data in ES)
3435 import pyodbc
36+ self ._pyodbc = pyodbc
3537
3638 def _reconstitute_csv (self , index_name ):
37- with pyodbc .connect (self ._dsn ) as cnxn :
39+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
3840 cnxn .autocommit = True
3941 csv = u""
4042 cols = self ._data .csv_attributes (index_name )[1 ]
@@ -69,7 +71,7 @@ def _as_csv(self, index_name):
6971 def _count_all (self , index_name ):
7072 print ("Counting records in index '%s.'" % index_name )
7173 cnt = 0
72- with pyodbc .connect (self ._dsn ) as cnxn :
74+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
7375 cnxn .autocommit = True
7476 with cnxn .execute ("select 1 from %s" % index_name ) as curs :
7577 while curs .fetchone ():
@@ -81,7 +83,7 @@ def _count_all(self, index_name):
8183
8284 def _clear_cursor (self , index_name ):
8385 conn_str = self ._dsn + ";MaxFetchSize=5"
84- with pyodbc .connect (conn_str ) as cnxn :
86+ with self . _pyodbc .connect (conn_str ) as cnxn :
8587 cnxn .autocommit = True
8688 with cnxn .execute ("select 1 from %s limit 10" % index_name ) as curs :
8789 for i in range (3 ): # must be lower than MaxFetchSize, so no next page be requested
@@ -93,7 +95,7 @@ def _clear_cursor(self, index_name):
9395
9496 def _select_columns (self , index_name , columns ):
9597 print ("Selecting columns '%s' from index '%s'." % (columns , index_name ))
96- with pyodbc .connect (self ._dsn ) as cnxn :
98+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
9799 cnxn .autocommit = True
98100 stmt = "select %s from %s" % (columns , index_name )
99101 with cnxn .execute (stmt ) as curs :
@@ -103,14 +105,14 @@ def _select_columns(self, index_name, columns):
103105 print ("Selected %s rows from %s." % (cnt , index_name ))
104106
105107 def _check_info (self , attr , expected ):
106- with pyodbc .connect (self ._dsn ) as cnxn :
108+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
107109 cnxn .autocommit = True
108110 value = cnxn .getinfo (attr )
109111 self .assertEqual (value , expected )
110112
111113 # tables(table=None, catalog=None, schema=None, tableType=None)
112114 def _catalog_tables (self , no_table_type_as = "" ):
113- with pyodbc .connect (self ._dsn ) as cnxn :
115+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
114116 cnxn .autocommit = True
115117 curs = cnxn .cursor ()
116118
@@ -140,7 +142,7 @@ def _catalog_tables(self, no_table_type_as=""):
140142 # use_surrogate: pyodbc seems to not reliably null-terminate the catalog and/or table name string,
141143 # despite indicating so.
142144 def _catalog_columns (self , use_catalog = False , use_surrogate = True ):
143- with pyodbc .connect (self ._dsn ) as cnxn :
145+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
144146 cnxn .autocommit = True
145147 curs = cnxn .cursor ()
146148 if not use_surrogate :
@@ -248,7 +250,7 @@ def _type_to_instance(self, data_type, data_val):
248250
249251 def _proto_tests (self ):
250252 tests = self ._data .proto_tests ()
251- with pyodbc .connect (self ._dsn ) as cnxn :
253+ with self . _pyodbc .connect (self ._dsn ) as cnxn :
252254 cnxn .autocommit = True
253255 self ._install_output_converters (cnxn )
254256 try :
@@ -279,8 +281,8 @@ def _proto_tests(self):
279281 cnxn .clear_output_converters ()
280282
281283 def perform (self ):
282- self ._check_info (pyodbc .SQL_USER_NAME , UID )
283- self ._check_info (pyodbc .SQL_DATABASE_NAME , CATALOG )
284+ self ._check_info (self . _pyodbc .SQL_USER_NAME , UID )
285+ self ._check_info (self . _pyodbc .SQL_DATABASE_NAME , CATALOG )
284286
285287 # simulate catalog querying as apps do in ES/GH#40775 do
286288 self ._catalog_tables (no_table_type_as = "" )
0 commit comments