Skip to content

Commit d75194a

Browse files
authored
Sync with sdk setup from setUpClass to setUp (#1193)
1 parent 2ce69a6 commit d75194a

File tree

21 files changed

+151
-170
lines changed

21 files changed

+151
-170
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'release/*'
77
pull_request:
88
env:
9-
CORE_REPO_SHA: 05d251c5d6baefe2f084e7361cb144c4fa10da96
9+
CORE_REPO_SHA: c09f2076a1878c6d58b78d3895485ef5559f30f7
1010

1111
jobs:
1212
build:
@@ -42,7 +42,7 @@ jobs:
4242
path: |
4343
.tox
4444
~/.cache/pip
45-
key: v6-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
45+
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
4646
- name: run tox
4747
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
4848
# - name: Find and merge ${{ matrix.package }} benchmarks
@@ -118,7 +118,7 @@ jobs:
118118
path: |
119119
.tox
120120
~/.cache/pip
121-
key: v6-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
121+
key: v7-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
122122
- name: run tox
123123
run: tox -e ${{ matrix.tox-environment }}
124124
- name: Ensure generated code is up to date

instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def get_dsn_parameters(self): # pylint: disable=no-self-use
6868

6969
class TestPostgresqlIntegration(TestBase):
7070
def setUp(self):
71+
super().setUp()
7172
self.cursor_mock = mock.patch(
7273
"opentelemetry.instrumentation.psycopg2.pg_cursor", MockCursor
7374
)

instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def _instrument(self, **kwargs):
223223
request_hook = kwargs.get("request_hook", dummy_callback)
224224
response_hook = kwargs.get("response_hook", dummy_callback)
225225
failed_hook = kwargs.get("failed_hook", dummy_callback)
226-
227226
# Create and register a CommandTracer only the first time
228227
if self._commandtracer_instance is None:
229228
tracer = get_tracer(__name__, __version__, tracer_provider)
@@ -235,7 +234,6 @@ def _instrument(self, **kwargs):
235234
failed_hook=failed_hook,
236235
)
237236
monitoring.register(self._commandtracer_instance)
238-
239237
# If already created, just enable it
240238
self._commandtracer_instance.is_enabled = True
241239

instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121

2222

2323
class TestRedis(TestBase):
24+
def setUp(self):
25+
super().setUp()
26+
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
27+
28+
def tearDown(self):
29+
super().tearDown()
30+
RedisInstrumentor().uninstrument()
31+
2432
def test_span_properties(self):
2533
redis_client = redis.Redis()
26-
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
2734

2835
with mock.patch.object(redis_client, "connection"):
2936
redis_client.get("key")
@@ -36,7 +43,6 @@ def test_span_properties(self):
3643

3744
def test_not_recording(self):
3845
redis_client = redis.Redis()
39-
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
4046

4147
mock_tracer = mock.Mock()
4248
mock_span = mock.Mock()
@@ -53,7 +59,6 @@ def test_not_recording(self):
5359

5460
def test_instrument_uninstrument(self):
5561
redis_client = redis.Redis()
56-
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
5762

5863
with mock.patch.object(redis_client, "connection"):
5964
redis_client.get("key")

instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def setUp(self):
3535

3636
broker.declare_actor(actor_div)
3737

38+
def tearDown(self):
39+
RemouladeInstrumentor().uninstrument()
40+
super().tearDown()
41+
3842
def test_message(self):
3943
actor_div.send(2, 3)
4044

instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,26 @@
2121

2222

2323
class TestSQLite3(TestBase):
24-
@classmethod
25-
def setUpClass(cls):
26-
super().setUpClass()
27-
cls._connection = None
28-
cls._cursor = None
29-
cls._connection2 = None
30-
cls._cursor2 = None
31-
cls._tracer = cls.tracer_provider.get_tracer(__name__)
32-
SQLite3Instrumentor().instrument(tracer_provider=cls.tracer_provider)
33-
cls._connection = sqlite3.connect(":memory:")
34-
cls._cursor = cls._connection.cursor()
35-
cls._connection2 = dbapi2.connect(":memory:")
36-
cls._cursor2 = cls._connection2.cursor()
24+
def setUp(self):
25+
super().setUp()
26+
SQLite3Instrumentor().instrument(tracer_provider=self.tracer_provider)
27+
self._tracer = self.tracer_provider.get_tracer(__name__)
28+
self._connection = sqlite3.connect(":memory:")
29+
self._cursor = self._connection.cursor()
30+
self._connection2 = dbapi2.connect(":memory:")
31+
self._cursor2 = self._connection2.cursor()
3732

38-
@classmethod
39-
def tearDownClass(cls):
40-
if cls._cursor:
41-
cls._cursor.close()
42-
if cls._connection:
43-
cls._connection.close()
44-
if cls._cursor2:
45-
cls._cursor2.close()
46-
if cls._connection2:
47-
cls._connection2.close()
33+
def tearDown(self):
34+
super().tearDown()
35+
if self._cursor:
36+
self._cursor.close()
37+
if self._connection:
38+
self._connection.close()
39+
if self._cursor2:
40+
self._cursor2.close()
41+
if self._connection2:
42+
self._connection2.close()
43+
SQLite3Instrumentor().uninstrument()
4844

4945
def validate_spans(self, span_name):
5046
spans = self.memory_exporter.get_finished_spans()
@@ -65,6 +61,12 @@ def validate_spans(self, span_name):
6561
self.assertIs(child_span.parent, root_span.get_span_context())
6662
self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT)
6763

64+
def _create_tables(self):
65+
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
66+
self._cursor.execute(stmt)
67+
self._cursor2.execute(stmt)
68+
self.memory_exporter.clear()
69+
6870
def test_execute(self):
6971
"""Should create a child span for execute method"""
7072
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
@@ -78,6 +80,9 @@ def test_execute(self):
7880

7981
def test_executemany(self):
8082
"""Should create a child span for executemany"""
83+
self._create_tables()
84+
85+
# real spans for executemany
8186
stmt = "INSERT INTO test (id) VALUES (?)"
8287
data = [("1",), ("2",), ("3",)]
8388
with self._tracer.start_as_current_span("rootSpan"):

instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,7 @@ def test_mark_span_internal_in_presence_of_span_from_other_framework(self):
508508
class TestAdditionOfCustomRequestResponseHeaders(WsgiTestBase):
509509
def setUp(self):
510510
super().setUp()
511-
tracer_provider, _ = TestBase.create_tracer_provider()
512-
self.tracer = tracer_provider.get_tracer(__name__)
511+
self.tracer = self.tracer_provider.get_tracer(__name__)
513512

514513
def iterate_response(self, response):
515514
while True:

opentelemetry-instrumentation/tests/test_dependencies.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727

2828
class TestDependencyConflicts(TestBase):
29-
def setUp(self):
30-
pass
31-
3229
def test_get_dependency_conflicts_empty(self):
3330
self.assertIsNone(get_dependency_conflicts([]))
3431

opentelemetry-instrumentation/tests/test_propagators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
# pylint: disable=protected-access
1616

17+
import unittest
18+
1719
from opentelemetry import trace
1820
from opentelemetry.instrumentation import propagators
1921
from opentelemetry.instrumentation.propagators import (
@@ -39,7 +41,7 @@ def test_get_set(self):
3941
propagators._RESPONSE_PROPAGATOR = original
4042

4143

42-
class TestDictHeaderSetter(TestBase):
44+
class TestDictHeaderSetter(unittest.TestCase):
4345
def test_simple(self):
4446
setter = DictHeaderSetter()
4547
carrier = {}

opentelemetry-instrumentation/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import unittest
1516
from http import HTTPStatus
1617

1718
from opentelemetry.instrumentation.utils import (
1819
_python_path_without_directory,
1920
http_status_to_status_code,
2021
)
21-
from opentelemetry.test.test_base import TestBase
2222
from opentelemetry.trace import StatusCode
2323

2424

25-
class TestUtils(TestBase):
25+
class TestUtils(unittest.TestCase):
2626
# See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status
2727
def test_http_status_to_status_code(self):
2828
for status_code, expected in (

tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ def async_call(coro):
2121

2222

2323
class TestFunctionalAsyncPG(TestBase):
24-
@classmethod
25-
def setUpClass(cls):
26-
super().setUpClass()
27-
cls._connection = None
28-
cls._cursor = None
29-
cls._tracer = cls.tracer_provider.get_tracer(__name__)
30-
AsyncPGInstrumentor().instrument(tracer_provider=cls.tracer_provider)
31-
cls._connection = async_call(
24+
def setUp(self):
25+
super().setUp()
26+
self._tracer = self.tracer_provider.get_tracer(__name__)
27+
AsyncPGInstrumentor().instrument(tracer_provider=self.tracer_provider)
28+
self._connection = async_call(
3229
asyncpg.connect(
3330
database=POSTGRES_DB_NAME,
3431
user=POSTGRES_USER,
@@ -38,9 +35,9 @@ def setUpClass(cls):
3835
)
3936
)
4037

41-
@classmethod
42-
def tearDownClass(cls):
38+
def tearDown(self):
4339
AsyncPGInstrumentor().uninstrument()
40+
super().tearDown()
4441

4542
def check_span(self, span):
4643
self.assertEqual(
@@ -148,16 +145,13 @@ def test_instrumented_method_doesnt_capture_parameters(self, *_, **__):
148145

149146

150147
class TestFunctionalAsyncPG_CaptureParameters(TestBase):
151-
@classmethod
152-
def setUpClass(cls):
153-
super().setUpClass()
154-
cls._connection = None
155-
cls._cursor = None
156-
cls._tracer = cls.tracer_provider.get_tracer(__name__)
148+
def setUp(self):
149+
super().setUp()
150+
self._tracer = self.tracer_provider.get_tracer(__name__)
157151
AsyncPGInstrumentor(capture_parameters=True).instrument(
158-
tracer_provider=cls.tracer_provider
152+
tracer_provider=self.tracer_provider
159153
)
160-
cls._connection = async_call(
154+
self._connection = async_call(
161155
asyncpg.connect(
162156
database=POSTGRES_DB_NAME,
163157
user=POSTGRES_USER,
@@ -167,9 +161,9 @@ def setUpClass(cls):
167161
)
168162
)
169163

170-
@classmethod
171-
def tearDownClass(cls):
164+
def tearDown(self):
172165
AsyncPGInstrumentor().uninstrument()
166+
super().tearDown()
173167

174168
def check_span(self, span):
175169
self.assertEqual(

tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,10 @@
2929

3030

3131
class TestFunctionalMysql(TestBase):
32-
@classmethod
33-
def setUpClass(cls):
34-
super().setUpClass()
35-
cls._connection = None
36-
cls._cursor = None
37-
cls._tracer = cls.tracer_provider.get_tracer(__name__)
38-
MySQLInstrumentor().instrument()
39-
40-
@classmethod
41-
def tearDownClass(cls):
42-
if cls._connection:
43-
cls._connection.close()
44-
MySQLInstrumentor().uninstrument()
45-
4632
def setUp(self):
4733
super().setUp()
34+
self._tracer = self.tracer_provider.get_tracer(__name__)
35+
MySQLInstrumentor().instrument()
4836
self._connection = mysql.connector.connect(
4937
user=MYSQL_USER,
5038
password=MYSQL_PASSWORD,
@@ -54,6 +42,12 @@ def setUp(self):
5442
)
5543
self._cursor = self._connection.cursor()
5644

45+
def tearDown(self):
46+
self._cursor.close()
47+
self._connection.close()
48+
MySQLInstrumentor().uninstrument()
49+
super().tearDown()
50+
5751
def validate_spans(self, span_name):
5852
spans = self.memory_exporter.get_finished_spans()
5953
self.assertEqual(len(spans), 2)

0 commit comments

Comments
 (0)