From bd39b36b82b0ecef890d4f3bae67339d6643c4c2 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Wed, 18 Nov 2020 01:36:16 +0530 Subject: [PATCH] Fix tests for sqlite --- .../tests/test_sqlite3.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index 0e385cf3e..a4fc88706 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -37,7 +37,7 @@ class TestSQLite3(TestBase): if cls._connection: cls._connection.close() - def validate_spans(self): + def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 2) for span in spans: @@ -50,34 +50,30 @@ class TestSQLite3(TestBase): self.assertIsNotNone(root_span) self.assertIsNotNone(child_span) self.assertEqual(root_span.name, "rootSpan") - self.assertEqual(child_span.name, "sqlite3") + self.assertEqual(child_span.name, span_name) self.assertIsNotNone(child_span.parent) self.assertIs(child_span.parent, root_span.get_span_context()) self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) def test_execute(self): - """Should create a child span for execute method - """ + """Should create a child span for execute method""" + stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" with self._tracer.start_as_current_span("rootSpan"): - self._cursor.execute( - "CREATE TABLE IF NOT EXISTS test (id integer)" - ) - self.validate_spans() + self._cursor.execute(stmt) + self.validate_spans(stmt) def test_executemany(self): - """Should create a child span for executemany - """ + """Should create a child span for executemany""" + stmt = "INSERT INTO test (id) VALUES (?)" with self._tracer.start_as_current_span("rootSpan"): data = [("1",), ("2",), ("3",)] - stmt = "INSERT INTO test (id) VALUES (?)" self._cursor.executemany(stmt, data) - self.validate_spans() + self.validate_spans(stmt) def test_callproc(self): - """Should create a child span for callproc - """ + """Should create a child span for callproc""" with self._tracer.start_as_current_span("rootSpan"), self.assertRaises( Exception ): self._cursor.callproc("test", ()) - self.validate_spans() + self.validate_spans("test")