mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 11:31:52 +08:00
Update tests to work with SQLAlchemy 2 (#2976)
This commit is contained in:
@ -14,7 +14,10 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import (
|
||||
create_engine,
|
||||
text,
|
||||
)
|
||||
|
||||
from opentelemetry import context
|
||||
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
|
||||
@ -37,7 +40,7 @@ class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase):
|
||||
engine=engine, tracer_provider=self.tracer_provider
|
||||
)
|
||||
cnx = engine.connect()
|
||||
cnx.execute("SELECT 1;").fetchall()
|
||||
cnx.execute(text("SELECT 1;")).fetchall()
|
||||
|
||||
self.assertEqual(self.caplog.records[-2].getMessage(), "SELECT 1;")
|
||||
|
||||
@ -50,7 +53,7 @@ class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase):
|
||||
commenter_options={"db_framework": False},
|
||||
)
|
||||
cnx = engine.connect()
|
||||
cnx.execute("SELECT 1;").fetchall()
|
||||
cnx.execute(text("SELECT 1;")).fetchall()
|
||||
self.assertRegex(
|
||||
self.caplog.records[-2].getMessage(),
|
||||
r"SELECT 1 /\*db_driver='(.*)',traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
|
||||
@ -68,7 +71,7 @@ class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase):
|
||||
},
|
||||
)
|
||||
cnx = engine.connect()
|
||||
cnx.execute("SELECT 1;").fetchall()
|
||||
cnx.execute(text("SELECT 1;")).fetchall()
|
||||
self.assertRegex(
|
||||
self.caplog.records[-2].getMessage(),
|
||||
r"SELECT 1 /\*db_driver='(.*)'\*/;",
|
||||
@ -90,7 +93,7 @@ class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase):
|
||||
)
|
||||
context.attach(sqlcommenter_context)
|
||||
|
||||
cnx.execute("SELECT 1;").fetchall()
|
||||
cnx.execute(text("SELECT 1;")).fetchall()
|
||||
self.assertRegex(
|
||||
self.caplog.records[-2].getMessage(),
|
||||
r"SELECT 1 /\*db_driver='(.*)',flask=1,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
|
||||
@ -105,7 +108,7 @@ class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase):
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
cnx = engine.connect()
|
||||
cnx.execute("SELECT 1;").fetchall()
|
||||
cnx.execute(text("SELECT 1;")).fetchall()
|
||||
self.assertRegex(
|
||||
self.caplog.records[-2].getMessage(),
|
||||
r"SELECT 1 /\*db_driver='(.*)',traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
|
||||
@ -120,5 +123,5 @@ class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase):
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
cnx = engine.connect()
|
||||
cnx.execute("SELECT 1;").fetchall()
|
||||
cnx.execute(text("SELECT 1;")).fetchall()
|
||||
self.assertEqual(self.caplog.records[-2].getMessage(), "SELECT 1;")
|
||||
|
Reference in New Issue
Block a user