Skip to content

Commit ed1db9d

Browse files
committed
removed tearDown, added connection.close() to first test
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent 49082fb commit ed1db9d

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

tests/unit/test_client.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,43 +83,43 @@ class ClientTestSuite(unittest.TestCase):
8383
"access_token": "tok",
8484
}
8585

86-
def setUp(self):
87-
"""Set up connection tracking before each test"""
88-
self.tracked_connections = []
86+
# def setUp(self):
87+
# """Set up connection tracking before each test"""
88+
# self.tracked_connections = []
8989

90-
# Store the original connect function
91-
self.original_connect = databricks.sql.connect
90+
# # Store the original connect function
91+
# self.original_connect = databricks.sql.connect
9292

93-
def patched_connect(*args, **kwargs):
94-
"""Wrapper that tracks all created connections"""
95-
conn = self.original_connect(*args, **kwargs)
93+
# def patched_connect(*args, **kwargs):
94+
# """Wrapper that tracks all created connections"""
95+
# conn = self.original_connect(*args, **kwargs)
9696

97-
# Skip tracking for finalizer tests to allow garbage collection
98-
if not (hasattr(self, '_testMethodName') and 'finalizer' in self._testMethodName):
99-
self.tracked_connections.append(conn)
97+
# # Skip tracking for finalizer tests to allow garbage collection
98+
# if not (hasattr(self, '_testMethodName') and 'finalizer' in self._testMethodName):
99+
# self.tracked_connections.append(conn)
100100

101-
return conn
101+
# return conn
102102

103-
# Apply the patch to track connections
104-
self.connect_patcher = patch('databricks.sql.connect', patched_connect)
105-
self.connect_patcher.start()
103+
# # Apply the patch to track connections
104+
# self.connect_patcher = patch('databricks.sql.connect', patched_connect)
105+
# self.connect_patcher.start()
106106

107-
def tearDown(self):
108-
"""Clean up connections after each test"""
109-
# Close all tracked connections
110-
for conn in self.tracked_connections:
111-
try:
112-
if hasattr(conn, 'open') and conn.open:
113-
conn.close()
114-
except Exception as e:
115-
# Log the error but don't fail the test
116-
print(f"Warning: Error closing connection in tearDown: {e}")
107+
# def tearDown(self):
108+
# """Clean up connections after each test"""
109+
# # Close all tracked connections
110+
# for conn in self.tracked_connections:
111+
# try:
112+
# if hasattr(conn, 'open') and conn.open:
113+
# conn.close()
114+
# except Exception as e:
115+
# # Log the error but don't fail the test
116+
# print(f"Warning: Error closing connection in tearDown: {e}")
117117

118-
# Stop the connect patcher
119-
self.connect_patcher.stop()
118+
# # Stop the connect patcher
119+
# self.connect_patcher.stop()
120120

121-
# Clear the tracked connections list
122-
self.tracked_connections.clear()
121+
# # Clear the tracked connections list
122+
# self.tracked_connections.clear()
123123

124124
@patch("%s.client.ThriftBackend" % PACKAGE_NAME)
125125
def test_close_uses_the_correct_session_id(self, mock_client_class):
@@ -790,6 +790,7 @@ def test_access_current_query_id(self):
790790

791791
cursor.close()
792792
self.assertIsNone(cursor.query_id)
793+
connection.close()
793794

794795
def test_cursor_close_handles_exception(self):
795796
"""Test that Cursor.close() handles exceptions from close_command properly."""

0 commit comments

Comments
 (0)