Skip to content

Commit 40c2ba7

Browse files
committed
More fixes
1 parent f5646b8 commit 40c2ba7

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def test_executemany_comment(self):
279279
connect_module = mock.MagicMock()
280280
connect_module.__name__ = "test"
281281
connect_module.__version__ = mock.MagicMock()
282-
connect_module.__libpq_version__ = 123
282+
connect_module.pq.version.return_value = 123
283283
connect_module.apilevel = 123
284284
connect_module.threadsafety = 123
285285
connect_module.paramstyle = "test"
@@ -312,7 +312,7 @@ def test_executemany_comment_stmt_enabled(self):
312312
connect_module = mock.MagicMock()
313313
connect_module.__name__ = "test"
314314
connect_module.__version__ = mock.MagicMock()
315-
connect_module.__libpq_version__ = 123
315+
connect_module.pq.version.return_value = 123
316316
connect_module.apilevel = 123
317317
connect_module.threadsafety = 123
318318
connect_module.paramstyle = "test"
@@ -420,7 +420,7 @@ def test_executemany_comment_stmt_enabled_matches_db_statement_attribute(
420420
):
421421
connect_module = mock.MagicMock()
422422
connect_module.__version__ = mock.MagicMock()
423-
connect_module.__libpq_version__ = 123
423+
connect_module.pq.version.return_value = 123
424424
connect_module.apilevel = 123
425425
connect_module.threadsafety = 123
426426
connect_module.paramstyle = "test"
@@ -564,6 +564,7 @@ def test_executemany_psycopg2_integration_comment(self):
564564
connect_module = mock.MagicMock()
565565
connect_module.__name__ = "psycopg2"
566566
connect_module.__version__ = "1.2.3"
567+
connect_module.pq.version.side_effect = AttributeError
567568
connect_module.__libpq_version__ = 123
568569
connect_module.apilevel = 123
569570
connect_module.threadsafety = 123
@@ -597,6 +598,7 @@ def test_executemany_psycopg2_integration_comment_stmt_enabled(self):
597598
connect_module = mock.MagicMock()
598599
connect_module.__name__ = "psycopg2"
599600
connect_module.__version__ = "1.2.3"
601+
connect_module.pq.version.side_effect = AttributeError
600602
connect_module.__libpq_version__ = 123
601603
connect_module.apilevel = 123
602604
connect_module.threadsafety = 123
@@ -934,7 +936,7 @@ def test_executemany_flask_integration_comment(self):
934936
sqlcommenter_context = context.set_value(
935937
"SQLCOMMENTER_ORM_TAGS_AND_VALUES", {"flask": 1}, current_context
936938
)
937-
context.attach(sqlcommenter_context)
939+
token = context.attach(sqlcommenter_context)
938940

939941
mock_connection = db_integration.wrapped_connection(
940942
mock_connect, {}, {}
@@ -953,16 +955,13 @@ def test_executemany_flask_integration_comment(self):
953955
"Select 1;",
954956
)
955957

956-
clear_context = context.set_value(
957-
"SQLCOMMENTER_ORM_TAGS_AND_VALUES", {}, current_context
958-
)
959-
context.attach(clear_context)
958+
context.detach(token)
960959

961960
def test_executemany_flask_integration_comment_stmt_enabled(self):
962961
connect_module = mock.MagicMock()
963962
connect_module.__name__ = "test"
964963
connect_module.__version__ = mock.MagicMock()
965-
connect_module.__libpq_version__ = 123
964+
connect_module.pq.version.return_value = 123
966965
connect_module.apilevel = 123
967966
connect_module.threadsafety = 123
968967
connect_module.paramstyle = "test"
@@ -979,7 +978,7 @@ def test_executemany_flask_integration_comment_stmt_enabled(self):
979978
sqlcommenter_context = context.set_value(
980979
"SQLCOMMENTER_ORM_TAGS_AND_VALUES", {"flask": 1}, current_context
981980
)
982-
context.attach(sqlcommenter_context)
981+
token = context.attach(sqlcommenter_context)
983982

984983
mock_connection = db_integration.wrapped_connection(
985984
mock_connect, {}, {}
@@ -998,10 +997,7 @@ def test_executemany_flask_integration_comment_stmt_enabled(self):
998997
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',flask=1,libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
999998
)
1000999

1001-
clear_context = context.set_value(
1002-
"SQLCOMMENTER_ORM_TAGS_AND_VALUES", {}, current_context
1003-
)
1004-
context.attach(clear_context)
1000+
context.detach(token)
10051001

10061002
def test_callproc(self):
10071003
db_integration = dbapi.DatabaseApiIntegration(
@@ -1126,7 +1122,7 @@ def test_non_string_sql_conversion(self):
11261122
connect_module = mock.MagicMock()
11271123
connect_module.__name__ = "test"
11281124
connect_module.__version__ = "1.0"
1129-
connect_module.__libpq_version__ = 123
1125+
connect_module.pq.version.return_value = 123
11301126
connect_module.apilevel = "2.0"
11311127
connect_module.threadsafety = 1
11321128
connect_module.paramstyle = "test"

0 commit comments

Comments
 (0)