From 270d0bc7332a577a2932f21be93a82b70403e187 Mon Sep 17 00:00:00 2001 From: rite7sh Date: Thu, 22 Jan 2026 03:10:43 +0530 Subject: [PATCH 1/8] test(mysql): provide concrete DBAPI connection attributes in mocks --- .../tests/test_mysql_integration.py | 91 ++++++++++++++++++- 1 file changed, 86 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index f97e97692e..79c324c4c6 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -28,6 +28,10 @@ def connect_and_execute_query(): cnx = mysql.connector.connect(database="test") + cnx.database = "test" + cnx.host = "localhost" + cnx.port = 3306 + # Provide set values to avoid Magicbook attribute warnings cursor = cnx.cursor() query = "SELECT * FROM test" cursor.execute(query) @@ -35,6 +39,22 @@ def connect_and_execute_query(): return cnx, query +def make_mysql_connection_mock(): + cnx = mock.MagicMock() + cnx.database = "test" + cnx.host = "localhost" + cnx.port = 3306 + + cursor = mock.MagicMock() + cursor._cnx = mock.MagicMock() + cursor._cnx.host = "localhost" + cursor._cnx.port = 3306 + cursor._cnx.database = "test" + + cnx.cursor.return_value = cursor + return cnx + + class TestMysqlIntegration(TestBase): def tearDown(self): super().tearDown() @@ -44,6 +64,7 @@ def tearDown(self): @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_instrumentor(self, mock_connect): + mock_connect.return_value = make_mysql_connection_mock() MySQLInstrumentor().instrument() connect_and_execute_query() @@ -68,6 +89,7 @@ def test_instrumentor(self, mock_connect): @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_custom_tracer_provider(self, mock_connect): + mock_connect.return_value = make_mysql_connection_mock() resource = resources.Resource.create({}) result = self.create_tracer_provider(resource=resource) tracer_provider, exporter = result @@ -84,6 +106,7 @@ def test_custom_tracer_provider(self, mock_connect): @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_instrument_connection(self, mock_connect): + mock_connect.return_value = make_mysql_connection_mock() cnx, query = connect_and_execute_query() spans_list = self.memory_exporter.get_finished_spans() @@ -98,6 +121,7 @@ def test_instrument_connection(self, mock_connect): @mock.patch("mysql.connector.connect") def test_instrument_connection_no_op_tracer_provider(self, mock_connect): + mock_connect.return_value = make_mysql_connection_mock() tracer_provider = trace_api.NoOpTracerProvider() MySQLInstrumentor().instrument(tracer_provider=tracer_provider) connect_and_execute_query() @@ -137,7 +161,15 @@ def test_instrument_connection_with_dbapi_sqlcomment_enabled(self): ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -175,7 +207,15 @@ def test_instrument_connection_with_dbapi_sqlcomment_enabled_stmt_enabled( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -214,7 +254,15 @@ def test_instrument_connection_with_dbapi_sqlcomment_enabled_with_options( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -257,8 +305,15 @@ def test_instrument_connection_with_dbapi_sqlcomment_not_enabled_default( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - mock_cursor = mock_connect_module.connect().cursor() + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -310,8 +365,15 @@ def test_instrument_with_dbapi_sqlcomment_enabled( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - mock_cursor = mock_connect_module.connect().cursor() + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -350,8 +412,15 @@ def test_instrument_with_dbapi_sqlcomment_enabled_stmt_enabled( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - mock_cursor = mock_connect_module.connect().cursor() + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -391,7 +460,11 @@ def test_instrument_with_dbapi_sqlcomment_enabled_with_options( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - mock_cursor = mock_connect_module.connect().cursor() + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() mock_connection.cursor.return_value = mock_cursor @@ -436,8 +509,15 @@ def test_instrument_with_dbapi_sqlcomment_not_enabled_default( ) mock_cursor = mock_connect_module.connect().cursor() mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - mock_cursor = mock_connect_module.connect().cursor() + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor with mock.patch( @@ -462,6 +542,7 @@ def test_instrument_with_dbapi_sqlcomment_not_enabled_default( @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_uninstrument_connection(self, mock_connect): + mock_connect.return_value = make_mysql_connection_mock() MySQLInstrumentor().instrument() cnx, query = connect_and_execute_query() From 8cf29c7abf825ad34674b4bfaec4e16896c43930 Mon Sep 17 00:00:00 2001 From: rite7sh Date: Thu, 22 Jan 2026 15:42:39 +0530 Subject: [PATCH 2/8] test(mysql): pass concrete attributes via MagicMock helpers --- .../tests/test_mysql_integration.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 79c324c4c6..a7f2f3880b 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -40,16 +40,18 @@ def connect_and_execute_query(): def make_mysql_connection_mock(): - cnx = mock.MagicMock() - cnx.database = "test" - cnx.host = "localhost" - cnx.port = 3306 + cnx = mock.MagicMock( + database="test", + host="localhost", + port=3306, + ) cursor = mock.MagicMock() - cursor._cnx = mock.MagicMock() - cursor._cnx.host = "localhost" - cursor._cnx.port = 3306 - cursor._cnx.database = "test" + cursor._cnx = mock.MagicMock( + database="test", + host="localhost", + port=3306, + ) cnx.cursor.return_value = cursor return cnx From 98dc66c22dbed122622e4d148eea3f38cc00112d Mon Sep 17 00:00:00 2001 From: rite7sh Date: Fri, 23 Jan 2026 01:23:18 +0530 Subject: [PATCH 3/8] test(mysql): refactor mocks and remove redundant attribute assignments --- .../tests/test_mysql_integration.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index a7f2f3880b..a1b9f8e843 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -28,10 +28,6 @@ def connect_and_execute_query(): cnx = mysql.connector.connect(database="test") - cnx.database = "test" - cnx.host = "localhost" - cnx.port = 3306 - # Provide set values to avoid Magicbook attribute warnings cursor = cnx.cursor() query = "SELECT * FROM test" cursor.execute(query) From 8d49dd9d5f85b469dca69832e267dd6f8ffd9067 Mon Sep 17 00:00:00 2001 From: rite7sh Date: Mon, 26 Jan 2026 01:42:13 +0530 Subject: [PATCH 4/8] changelog: add mysql test mock fix entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f26a21d56..03224d454b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3982](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3982)) ### Fixed - +- `opentelemetry-instrumentation-mysql`: Refactor MySQL integration test mocks to use concrete DBAPI connection attributes, reducing noisy attribute type warnings. + ([#4116](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4116)) - `opentelemetry-instrumentation-asyncpg`: Hydrate span attributes before creation so samplers can filter on database details ([#3841](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3841)) - `opentelemetry-instrumentation-django`: Fix exemplars generation for `http.server.(request.)duration` From caa23e990bf5860b2311dff2218a529e2dd03f76 Mon Sep 17 00:00:00 2001 From: rite7sh Date: Tue, 27 Jan 2026 03:17:01 +0530 Subject: [PATCH 5/8] test(mysql): refactor SQL commenter mocks into helper --- .../tests/test_mysql_integration.py | 189 +++++------------- 1 file changed, 48 insertions(+), 141 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index a1b9f8e843..90fd4cf632 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -53,6 +53,38 @@ def make_mysql_connection_mock(): return cnx +def make_mysql_commenter_mocks(client_version="foobaz"): + """Create mock objects for MySQL connector with SQL commenter support. + + Args: + client_version: The MySQL client version string to return from get_client_info() + + Returns: + Tuple of (mock_connect_module, mock_connection, mock_cursor) + """ + mock_connect_module = mock.MagicMock( + __name__="mysql.connector", + __version__="foobar", + threadsafety="123", + apilevel="123", + paramstyle="test", + ) + mock_cursor = mock_connect_module.connect().cursor() + mock_cursor._cnx._cmysql.get_client_info.return_value = client_version + + mock_cursor._cnx.host = "localhost" + mock_cursor._cnx.port = 3306 + mock_cursor._cnx.database = "test" + + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.host = "localhost" + mock_connection.port = 3306 + mock_connection.cursor.return_value = mock_cursor + + return mock_connect_module, mock_connection, mock_cursor + + class TestMysqlIntegration(TestBase): def tearDown(self): super().tearDown() @@ -150,25 +182,9 @@ def test_instrument_connection_enable_commenter_dbapi_kwargs( self.assertEqual(kwargs["enable_attribute_commenter"], True) def test_instrument_connection_with_dbapi_sqlcomment_enabled(self): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -196,25 +212,9 @@ def test_instrument_connection_with_dbapi_sqlcomment_enabled(self): def test_instrument_connection_with_dbapi_sqlcomment_enabled_stmt_enabled( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -243,25 +243,9 @@ def test_instrument_connection_with_dbapi_sqlcomment_enabled_stmt_enabled( def test_instrument_connection_with_dbapi_sqlcomment_enabled_with_options( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -294,25 +278,9 @@ def test_instrument_connection_with_dbapi_sqlcomment_enabled_with_options( def test_instrument_connection_with_dbapi_sqlcomment_not_enabled_default( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -354,25 +322,9 @@ def test_instrument_enable_commenter_dbapi_kwargs( def test_instrument_with_dbapi_sqlcomment_enabled( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -401,25 +353,9 @@ def test_instrument_with_dbapi_sqlcomment_enabled( def test_instrument_with_dbapi_sqlcomment_enabled_stmt_enabled( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -449,22 +385,9 @@ def test_instrument_with_dbapi_sqlcomment_enabled_stmt_enabled( def test_instrument_with_dbapi_sqlcomment_enabled_with_options( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -498,25 +421,9 @@ def test_instrument_with_dbapi_sqlcomment_enabled_with_options( def test_instrument_with_dbapi_sqlcomment_not_enabled_default( self, ): - mock_connect_module = mock.MagicMock( - __name__="mysql.connector", - __version__="foobar", - threadsafety="123", - apilevel="123", - paramstyle="test", + mock_connect_module, mock_connection, mock_cursor = ( + make_mysql_commenter_mocks() ) - mock_cursor = mock_connect_module.connect().cursor() - mock_cursor._cnx._cmysql.get_client_info.return_value = "foobaz" - - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 - mock_connection.cursor.return_value = mock_cursor with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", From 15420f0b1ea6b59afd5e1ebaf00f7adf9ac3143c Mon Sep 17 00:00:00 2001 From: rite7sh Date: Wed, 18 Feb 2026 23:06:39 +0530 Subject: [PATCH 6/8] test(mysql): refactor SQL commenter mocks into helper - Introduce make_mysql_commenter_mocks helper - Remove duplicated MagicMock setup - Preserve test assertions and behavior - Improve readability and maintainability --- .../tests/test_mysql_integration.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 90fd4cf632..02d456e717 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -322,9 +322,7 @@ def test_instrument_enable_commenter_dbapi_kwargs( def test_instrument_with_dbapi_sqlcomment_enabled( self, ): - mock_connect_module, mock_connection, mock_cursor = ( - make_mysql_commenter_mocks() - ) + mock_connect_module, _, mock_cursor = make_mysql_commenter_mocks() with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -353,9 +351,7 @@ def test_instrument_with_dbapi_sqlcomment_enabled( def test_instrument_with_dbapi_sqlcomment_enabled_stmt_enabled( self, ): - mock_connect_module, mock_connection, mock_cursor = ( - make_mysql_commenter_mocks() - ) + mock_connect_module, _, mock_cursor = make_mysql_commenter_mocks() with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -385,9 +381,7 @@ def test_instrument_with_dbapi_sqlcomment_enabled_stmt_enabled( def test_instrument_with_dbapi_sqlcomment_enabled_with_options( self, ): - mock_connect_module, mock_connection, mock_cursor = ( - make_mysql_commenter_mocks() - ) + mock_connect_module, _, mock_cursor = make_mysql_commenter_mocks() with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", @@ -421,9 +415,7 @@ def test_instrument_with_dbapi_sqlcomment_enabled_with_options( def test_instrument_with_dbapi_sqlcomment_not_enabled_default( self, ): - mock_connect_module, mock_connection, mock_cursor = ( - make_mysql_commenter_mocks() - ) + mock_connect_module, _, mock_cursor = make_mysql_commenter_mocks() with mock.patch( "opentelemetry.instrumentation.mysql.mysql.connector", From 6faa1c0b3f81baa8fd64127ef2c2b885629acb6b Mon Sep 17 00:00:00 2001 From: rite7sh Date: Thu, 19 Feb 2026 14:10:45 +0530 Subject: [PATCH 7/8] test(mysql): use concrete DBAPI connection attributes in mocks to fix attribute type warnings --- .../tests/test_mysql_integration.py | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 02d456e717..f267f63946 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -36,18 +36,16 @@ def connect_and_execute_query(): def make_mysql_connection_mock(): - cnx = mock.MagicMock( - database="test", - host="localhost", - port=3306, - ) + cnx = mock.MagicMock() + cnx.database = "test" + cnx.server_host = "localhost" + cnx.server_port = 3306 cursor = mock.MagicMock() - cursor._cnx = mock.MagicMock( - database="test", - host="localhost", - port=3306, - ) + cursor._cnx = mock.MagicMock() + cursor._cnx.database = "test" + cursor._cnx.server_host = "localhost" + cursor._cnx.server_port = 3306 cnx.cursor.return_value = cursor return cnx @@ -69,18 +67,17 @@ def make_mysql_commenter_mocks(client_version="foobaz"): apilevel="123", paramstyle="test", ) + mock_connection = mock.MagicMock() + mock_connection.database = "test" + mock_connection.server_host = "localhost" + mock_connection.server_port = 3306 + mock_cursor = mock_connect_module.connect().cursor() + mock_cursor._cnx = mock_connection mock_cursor._cnx._cmysql.get_client_info.return_value = client_version - mock_cursor._cnx.host = "localhost" - mock_cursor._cnx.port = 3306 - mock_cursor._cnx.database = "test" - - mock_connection = mock.MagicMock() - mock_connection.database = "test" - mock_connection.host = "localhost" - mock_connection.port = 3306 mock_connection.cursor.return_value = mock_cursor + mock_connect_module.connect.return_value = mock_connection return mock_connect_module, mock_connection, mock_cursor From 9a5464021cb66223d1d80b5935bf82a5aceed2c0 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 20 Feb 2026 11:17:28 +0100 Subject: [PATCH 8/8] Update instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py --- .../tests/test_mysql_integration.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index f267f63946..2b95c76058 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -42,10 +42,7 @@ def make_mysql_connection_mock(): cnx.server_port = 3306 cursor = mock.MagicMock() - cursor._cnx = mock.MagicMock() - cursor._cnx.database = "test" - cursor._cnx.server_host = "localhost" - cursor._cnx.server_port = 3306 + cursor._cnx = cnx cnx.cursor.return_value = cursor return cnx