diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3cbc0bc877..69f9d25ee6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 05d251c5d6baefe2f084e7361cb144c4fa10da96 + CORE_REPO_SHA: c09f2076a1878c6d58b78d3895485ef5559f30f7 jobs: build: @@ -42,7 +42,7 @@ jobs: path: | .tox ~/.cache/pip - key: v6-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} + key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} - name: run tox run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json # - name: Find and merge ${{ matrix.package }} benchmarks @@ -118,7 +118,7 @@ jobs: path: | .tox ~/.cache/pip - key: v6-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }} + key: v7-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }} - name: run tox run: tox -e ${{ matrix.tox-environment }} - name: Ensure generated code is up to date diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index e974da7d60..f516a07882 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -68,6 +68,7 @@ def get_dsn_parameters(self): # pylint: disable=no-self-use class TestPostgresqlIntegration(TestBase): def setUp(self): + super().setUp() self.cursor_mock = mock.patch( "opentelemetry.instrumentation.psycopg2.pg_cursor", MockCursor ) diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py index 171979dbfe..ba3afae11f 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -223,7 +223,6 @@ def _instrument(self, **kwargs): request_hook = kwargs.get("request_hook", dummy_callback) response_hook = kwargs.get("response_hook", dummy_callback) failed_hook = kwargs.get("failed_hook", dummy_callback) - # Create and register a CommandTracer only the first time if self._commandtracer_instance is None: tracer = get_tracer(__name__, __version__, tracer_provider) @@ -235,7 +234,6 @@ def _instrument(self, **kwargs): failed_hook=failed_hook, ) monitoring.register(self._commandtracer_instance) - # If already created, just enable it self._commandtracer_instance.is_enabled = True diff --git a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py index 3780f0c245..3d5479e731 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py +++ b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py @@ -21,9 +21,16 @@ class TestRedis(TestBase): + def setUp(self): + super().setUp() + RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) + + def tearDown(self): + super().tearDown() + RedisInstrumentor().uninstrument() + def test_span_properties(self): redis_client = redis.Redis() - RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) with mock.patch.object(redis_client, "connection"): redis_client.get("key") @@ -36,7 +43,6 @@ def test_span_properties(self): def test_not_recording(self): redis_client = redis.Redis() - RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) mock_tracer = mock.Mock() mock_span = mock.Mock() @@ -53,7 +59,6 @@ def test_not_recording(self): def test_instrument_uninstrument(self): redis_client = redis.Redis() - RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) with mock.patch.object(redis_client, "connection"): redis_client.get("key") diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 4704111bdd..ff25b3f6de 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -35,6 +35,10 @@ def setUp(self): broker.declare_actor(actor_div) + def tearDown(self): + RemouladeInstrumentor().uninstrument() + super().tearDown() + def test_message(self): actor_div.send(2, 3) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index 714ca0ea02..581920232b 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -21,30 +21,26 @@ class TestSQLite3(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._connection2 = None - cls._cursor2 = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) - SQLite3Instrumentor().instrument(tracer_provider=cls.tracer_provider) - cls._connection = sqlite3.connect(":memory:") - cls._cursor = cls._connection.cursor() - cls._connection2 = dbapi2.connect(":memory:") - cls._cursor2 = cls._connection2.cursor() + def setUp(self): + super().setUp() + SQLite3Instrumentor().instrument(tracer_provider=self.tracer_provider) + self._tracer = self.tracer_provider.get_tracer(__name__) + self._connection = sqlite3.connect(":memory:") + self._cursor = self._connection.cursor() + self._connection2 = dbapi2.connect(":memory:") + self._cursor2 = self._connection2.cursor() - @classmethod - def tearDownClass(cls): - if cls._cursor: - cls._cursor.close() - if cls._connection: - cls._connection.close() - if cls._cursor2: - cls._cursor2.close() - if cls._connection2: - cls._connection2.close() + def tearDown(self): + super().tearDown() + if self._cursor: + self._cursor.close() + if self._connection: + self._connection.close() + if self._cursor2: + self._cursor2.close() + if self._connection2: + self._connection2.close() + SQLite3Instrumentor().uninstrument() def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() @@ -65,6 +61,12 @@ def validate_spans(self, span_name): self.assertIs(child_span.parent, root_span.get_span_context()) self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) + def _create_tables(self): + stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" + self._cursor.execute(stmt) + self._cursor2.execute(stmt) + self.memory_exporter.clear() + def test_execute(self): """Should create a child span for execute method""" stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" @@ -78,6 +80,9 @@ def test_execute(self): def test_executemany(self): """Should create a child span for executemany""" + self._create_tables() + + # real spans for executemany stmt = "INSERT INTO test (id) VALUES (?)" data = [("1",), ("2",), ("3",)] with self._tracer.start_as_current_span("rootSpan"): diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index 7bdfabc37f..eeaad4c3cb 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -508,8 +508,7 @@ def test_mark_span_internal_in_presence_of_span_from_other_framework(self): class TestAdditionOfCustomRequestResponseHeaders(WsgiTestBase): def setUp(self): super().setUp() - tracer_provider, _ = TestBase.create_tracer_provider() - self.tracer = tracer_provider.get_tracer(__name__) + self.tracer = self.tracer_provider.get_tracer(__name__) def iterate_response(self, response): while True: diff --git a/opentelemetry-instrumentation/tests/test_dependencies.py b/opentelemetry-instrumentation/tests/test_dependencies.py index a8acac62f4..04bcf476ea 100644 --- a/opentelemetry-instrumentation/tests/test_dependencies.py +++ b/opentelemetry-instrumentation/tests/test_dependencies.py @@ -26,9 +26,6 @@ class TestDependencyConflicts(TestBase): - def setUp(self): - pass - def test_get_dependency_conflicts_empty(self): self.assertIsNone(get_dependency_conflicts([])) diff --git a/opentelemetry-instrumentation/tests/test_propagators.py b/opentelemetry-instrumentation/tests/test_propagators.py index 62461aafa9..00ec65a128 100644 --- a/opentelemetry-instrumentation/tests/test_propagators.py +++ b/opentelemetry-instrumentation/tests/test_propagators.py @@ -14,6 +14,8 @@ # pylint: disable=protected-access +import unittest + from opentelemetry import trace from opentelemetry.instrumentation import propagators from opentelemetry.instrumentation.propagators import ( @@ -39,7 +41,7 @@ def test_get_set(self): propagators._RESPONSE_PROPAGATOR = original -class TestDictHeaderSetter(TestBase): +class TestDictHeaderSetter(unittest.TestCase): def test_simple(self): setter = DictHeaderSetter() carrier = {} diff --git a/opentelemetry-instrumentation/tests/test_utils.py b/opentelemetry-instrumentation/tests/test_utils.py index b7c9ecdc6e..e6fe80a347 100644 --- a/opentelemetry-instrumentation/tests/test_utils.py +++ b/opentelemetry-instrumentation/tests/test_utils.py @@ -12,17 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +import unittest from http import HTTPStatus from opentelemetry.instrumentation.utils import ( _python_path_without_directory, http_status_to_status_code, ) -from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode -class TestUtils(TestBase): +class TestUtils(unittest.TestCase): # See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status def test_http_status_to_status_code(self): for status_code, expected in ( diff --git a/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py b/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py index 9470f68b05..8111bce15e 100644 --- a/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py @@ -21,14 +21,11 @@ def async_call(coro): class TestFunctionalAsyncPG(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) - AsyncPGInstrumentor().instrument(tracer_provider=cls.tracer_provider) - cls._connection = async_call( + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) + AsyncPGInstrumentor().instrument(tracer_provider=self.tracer_provider) + self._connection = async_call( asyncpg.connect( database=POSTGRES_DB_NAME, user=POSTGRES_USER, @@ -38,9 +35,9 @@ def setUpClass(cls): ) ) - @classmethod - def tearDownClass(cls): + def tearDown(self): AsyncPGInstrumentor().uninstrument() + super().tearDown() def check_span(self, span): self.assertEqual( @@ -148,16 +145,13 @@ def test_instrumented_method_doesnt_capture_parameters(self, *_, **__): class TestFunctionalAsyncPG_CaptureParameters(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) AsyncPGInstrumentor(capture_parameters=True).instrument( - tracer_provider=cls.tracer_provider + tracer_provider=self.tracer_provider ) - cls._connection = async_call( + self._connection = async_call( asyncpg.connect( database=POSTGRES_DB_NAME, user=POSTGRES_USER, @@ -167,9 +161,9 @@ def setUpClass(cls): ) ) - @classmethod - def tearDownClass(cls): + def tearDown(self): AsyncPGInstrumentor().uninstrument() + super().tearDown() def check_span(self, span): self.assertEqual( diff --git a/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py b/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py index 59cf401e03..4f1305e866 100644 --- a/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py +++ b/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py @@ -29,22 +29,10 @@ class TestFunctionalMysql(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) - MySQLInstrumentor().instrument() - - @classmethod - def tearDownClass(cls): - if cls._connection: - cls._connection.close() - MySQLInstrumentor().uninstrument() - def setUp(self): super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) + MySQLInstrumentor().instrument() self._connection = mysql.connector.connect( user=MYSQL_USER, password=MYSQL_PASSWORD, @@ -54,6 +42,12 @@ def setUp(self): ) self._cursor = self._connection.cursor() + def tearDown(self): + self._cursor.close() + self._connection.close() + MySQLInstrumentor().uninstrument() + super().tearDown() + def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 2) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py index 5f1d20bdc1..8157c06a32 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py @@ -36,14 +36,11 @@ def async_call(coro): class TestFunctionalAiopgConnect(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) - AiopgInstrumentor().instrument(tracer_provider=cls.tracer_provider) - cls._connection = async_call( + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) + AiopgInstrumentor().instrument(tracer_provider=self.tracer_provider) + self._connection = async_call( aiopg.connect( dbname=POSTGRES_DB_NAME, user=POSTGRES_USER, @@ -52,15 +49,13 @@ def setUpClass(cls): port=POSTGRES_PORT, ) ) - cls._cursor = async_call(cls._connection.cursor()) - - @classmethod - def tearDownClass(cls): - if cls._cursor: - cls._cursor.close() - if cls._connection: - cls._connection.close() + self._cursor = async_call(self._connection.cursor()) + + def tearDown(self): + self._cursor.close() + self._connection.close() AiopgInstrumentor().uninstrument() + super().tearDown() def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() @@ -121,18 +116,15 @@ def test_callproc(self): class TestFunctionalAiopgCreatePool(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) - AiopgInstrumentor().instrument(tracer_provider=cls.tracer_provider) - cls._dsn = ( + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) + AiopgInstrumentor().instrument(tracer_provider=self.tracer_provider) + self._dsn = ( f"dbname='{POSTGRES_DB_NAME}' user='{POSTGRES_USER}' password='{POSTGRES_PASSWORD}'" f" host='{POSTGRES_HOST}' port='{POSTGRES_PORT}'" ) - cls._pool = async_call( + self._pool = async_call( aiopg.create_pool( dbname=POSTGRES_DB_NAME, user=POSTGRES_USER, @@ -141,18 +133,15 @@ def setUpClass(cls): port=POSTGRES_PORT, ) ) - cls._connection = async_call(cls._pool.acquire()) - cls._cursor = async_call(cls._connection.cursor()) - - @classmethod - def tearDownClass(cls): - if cls._cursor: - cls._cursor.close() - if cls._connection: - cls._connection.close() - if cls._pool: - cls._pool.close() + self._connection = async_call(self._pool.acquire()) + self._cursor = async_call(self._connection.cursor()) + + def tearDown(self): + self._cursor.close() + self._connection.close() + self._pool.close() AiopgInstrumentor().uninstrument() + super().tearDown() def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py index 38ecff02e7..53112a5dbd 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py @@ -30,30 +30,25 @@ class TestFunctionalPsycopg(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) - Psycopg2Instrumentor().instrument(tracer_provider=cls.tracer_provider) - cls._connection = psycopg2.connect( + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) + Psycopg2Instrumentor().instrument(tracer_provider=self.tracer_provider) + self._connection = psycopg2.connect( dbname=POSTGRES_DB_NAME, user=POSTGRES_USER, password=POSTGRES_PASSWORD, host=POSTGRES_HOST, port=POSTGRES_PORT, ) - cls._connection.set_session(autocommit=True) - cls._cursor = cls._connection.cursor() - - @classmethod - def tearDownClass(cls): - if cls._cursor: - cls._cursor.close() - if cls._connection: - cls._connection.close() + self._connection.set_session(autocommit=True) + self._cursor = self._connection.cursor() + + def tearDown(self): + self._cursor.close() + self._connection.close() Psycopg2Instrumentor().uninstrument() + super().tearDown() def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py index 1e3460600e..9c84792256 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py @@ -26,30 +26,25 @@ class TestFunctionalPsycopg(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) Psycopg2Instrumentor().instrument(enable_commenter=True) - cls._connection = psycopg2.connect( + self._connection = psycopg2.connect( dbname=POSTGRES_DB_NAME, user=POSTGRES_USER, password=POSTGRES_PASSWORD, host=POSTGRES_HOST, port=POSTGRES_PORT, ) - cls._connection.set_session(autocommit=True) - cls._cursor = cls._connection.cursor() + self._connection.set_session(autocommit=True) + self._cursor = self._connection.cursor() - @classmethod - def tearDownClass(cls): - if cls._cursor: - cls._cursor.close() - if cls._connection: - cls._connection.close() + def tearDown(self): + self._cursor.close() + self._connection.close() Psycopg2Instrumentor().uninstrument() + super().tearDown() def test_commenter_enabled(self): self._cursor.execute("SELECT 1;") diff --git a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py index a716cd8def..92c694953b 100644 --- a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py @@ -28,16 +28,21 @@ class TestFunctionalPymongo(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._tracer = cls.tracer_provider.get_tracer(__name__) - PymongoInstrumentor().instrument() + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) + self.instrumentor = PymongoInstrumentor() + self.instrumentor.instrument() + self.instrumentor._commandtracer_instance._tracer = self._tracer client = MongoClient( MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000 ) db = client[MONGODB_DB_NAME] - cls._collection = db[MONGODB_COLLECTION_NAME] + self._collection = db[MONGODB_COLLECTION_NAME] + + def tearDown(self): + self.instrumentor.uninstrument() + super().tearDown() def validate_spans(self): spans = self.memory_exporter.get_finished_spans() diff --git a/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py b/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py index 881ef05d2a..83f7abf281 100644 --- a/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py @@ -29,27 +29,24 @@ class TestFunctionalPyMysql(TestBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._connection = None - cls._cursor = None - cls._tracer = cls.tracer_provider.get_tracer(__name__) + def setUp(self): + super().setUp() + self._tracer = self.tracer_provider.get_tracer(__name__) PyMySQLInstrumentor().instrument() - cls._connection = pymy.connect( + self._connection = pymy.connect( user=MYSQL_USER, password=MYSQL_PASSWORD, host=MYSQL_HOST, port=MYSQL_PORT, database=MYSQL_DB_NAME, ) - cls._cursor = cls._connection.cursor() + self._cursor = self._connection.cursor() - @classmethod - def tearDownClass(cls): - if cls._connection: - cls._connection.close() + def tearDown(self): + self._cursor.close() + self._connection.close() PyMySQLInstrumentor().uninstrument() + super().tearDown() def validate_spans(self, span_name): spans = self.memory_exporter.get_finished_spans() diff --git a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py index 6a4ef5021c..21d7e36b00 100644 --- a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py +++ b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py @@ -31,8 +31,8 @@ def setUp(self): RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) def tearDown(self): - super().tearDown() RedisInstrumentor().uninstrument() + super().tearDown() def _check_span(self, span, name): self.assertEqual(span.name, name) @@ -203,8 +203,8 @@ def setUp(self): RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) def tearDown(self): - super().tearDown() RedisInstrumentor().uninstrument() + super().tearDown() def _check_span(self, span, name): self.assertEqual(span.name, name) @@ -383,8 +383,8 @@ def setUp(self): RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) def tearDown(self): - super().tearDown() RedisInstrumentor().uninstrument() + super().tearDown() def _check_span(self, span, name): self.assertEqual(span.name, name) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py index 8c97d100e0..48944d58e0 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py @@ -35,6 +35,7 @@ class SQLAlchemyInstrumentTestCase(TestBase): """ def setUp(self): + super().setUp() # create a traced engine with the given arguments SQLAlchemyInstrumentor().instrument() dsn = ( @@ -45,23 +46,23 @@ def setUp(self): # prepare a connection self.conn = self.engine.connect() - super().setUp() def tearDown(self): # clear the database and dispose the engine self.conn.close() self.engine.dispose() SQLAlchemyInstrumentor().uninstrument() + super().tearDown() def test_engine_traced(self): # ensures that the engine is traced rows = self.conn.execute("SELECT").fetchall() self.assertEqual(len(rows), 1) - traces = self.memory_exporter.get_finished_spans() + spans = self.memory_exporter.get_finished_spans() # trace composition - self.assertEqual(len(traces), 1) - span = traces[0] + self.assertEqual(len(spans), 2) + span = spans[1] # check subset of span fields self.assertEqual(span.name, "SELECT opentelemetry-tests") self.assertIs(span.status.status_code, trace.StatusCode.UNSET) diff --git a/util/opentelemetry-util-http/tests/test_capture_custom_headers.py b/util/opentelemetry-util-http/tests/test_capture_custom_headers.py index eb1a4f6a7e..e6e1583ffb 100644 --- a/util/opentelemetry-util-http/tests/test_capture_custom_headers.py +++ b/util/opentelemetry-util-http/tests/test_capture_custom_headers.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import unittest from unittest.mock import patch -from opentelemetry.test.test_base import TestBase from opentelemetry.util.http import ( OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, @@ -24,7 +24,7 @@ ) -class TestCaptureCustomHeaders(TestBase): +class TestCaptureCustomHeaders(unittest.TestCase): @patch.dict( "os.environ", { diff --git a/util/opentelemetry-util-http/tests/test_http_excluded_urls.py b/util/opentelemetry-util-http/tests/test_http_excluded_urls.py index af524d2e7b..3fea381050 100644 --- a/util/opentelemetry-util-http/tests/test_http_excluded_urls.py +++ b/util/opentelemetry-util-http/tests/test_http_excluded_urls.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import unittest from unittest.mock import patch -from opentelemetry.test.test_base import TestBase from opentelemetry.util.http import get_excluded_urls -class TestGetExcludedUrls(TestBase): +class TestGetExcludedUrls(unittest.TestCase): @patch.dict( "os.environ", {