@@ -262,14 +262,14 @@ def test_callproc(self):
262
262
263
263
@mock .patch ("opentelemetry.instrumentation.dbapi" )
264
264
def test_wrap_connect (self , mock_dbapi ):
265
- dbapi .wrap_connect (self .tracer , mock_dbapi , "connect" , "-" )
265
+ dbapi .wrap_connect (self .tracer , MockConnectionEmpty () , "connect" , "-" )
266
266
connection = mock_dbapi .connect ()
267
267
self .assertEqual (mock_dbapi .connect .call_count , 1 )
268
- self .assertIsInstance (connection .__wrapped__ , mock .Mock )
268
+ self .assertIsInstance (connection ._connection , mock .Mock )
269
269
270
270
@mock .patch ("opentelemetry.instrumentation.dbapi" )
271
271
def test_unwrap_connect (self , mock_dbapi ):
272
- dbapi .wrap_connect (self .tracer , mock_dbapi , "connect" , "-" )
272
+ dbapi .wrap_connect (self .tracer , MockConnectionEmpty () , "connect" , "-" )
273
273
connection = mock_dbapi .connect ()
274
274
self .assertEqual (mock_dbapi .connect .call_count , 1 )
275
275
@@ -279,19 +279,19 @@ def test_unwrap_connect(self, mock_dbapi):
279
279
self .assertIsInstance (connection , mock .Mock )
280
280
281
281
def test_instrument_connection (self ):
282
- connection = mock . Mock ()
282
+ connection = MockConnectionEmpty ()
283
283
# Avoid get_attributes failing because can't concatenate mock
284
284
connection .database = "-"
285
285
connection2 = dbapi .instrument_connection (self .tracer , connection , "-" )
286
- self .assertIs (connection2 .__wrapped__ , connection )
286
+ self .assertIs (connection2 ._connection , connection )
287
287
288
288
def test_uninstrument_connection (self ):
289
- connection = mock . Mock ()
289
+ connection = MockConnectionEmpty ()
290
290
# Set connection.database to avoid a failure because mock can't
291
291
# be concatenated
292
292
connection .database = "-"
293
293
connection2 = dbapi .instrument_connection (self .tracer , connection , "-" )
294
- self .assertIs (connection2 .__wrapped__ , connection )
294
+ self .assertIs (connection2 ._connection , connection )
295
295
296
296
connection3 = dbapi .uninstrument_connection (connection2 )
297
297
self .assertIs (connection3 , connection )
@@ -307,10 +307,12 @@ def mock_connect(*args, **kwargs):
307
307
server_host = kwargs .get ("server_host" )
308
308
server_port = kwargs .get ("server_port" )
309
309
user = kwargs .get ("user" )
310
- return MockConnection (database , server_port , server_host , user )
310
+ return MockConnectionWithAttributes (
311
+ database , server_port , server_host , user
312
+ )
311
313
312
314
313
- class MockConnection :
315
+ class MockConnectionWithAttributes :
314
316
def __init__ (self , database , server_port , server_host , user ):
315
317
self .database = database
316
318
self .server_port = server_port
@@ -343,3 +345,7 @@ def executemany(self, query, params=None, throw_exception=False):
343
345
def callproc (self , query , params = None , throw_exception = False ):
344
346
if throw_exception :
345
347
raise Exception ("Test Exception" )
348
+
349
+
350
+ class MockConnectionEmpty :
351
+ pass
0 commit comments