Skip to content

Commit 3273d8c

Browse files
xrmxlzchen
andauthored
Fix asyncio related warnings in tests (#2335)
* aiopg: fix runtime warnings when running tests Fixes: RuntimeWarning: coroutine 'MockCursor.execute' was never awaited cursor.execute(query) * aio-pika: no need to return an awaitable in mocked method No need to return an awaitable since the mocked method awaits itself. Fixes: RuntimeWarning: coroutine 'sleep' was never awaited --------- Co-authored-by: Leighton Chen <[email protected]>
1 parent 9b3d0b4 commit 3273d8c

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

instrumentation/opentelemetry-instrumentation-aio-pika/tests/test_publish_decorator.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def _test_publish(self, exchange_type: Type[Exchange]):
7575
with mock.patch.object(
7676
PublishDecorator, "_get_publish_span"
7777
) as mock_get_publish_span:
78-
with mock.patch.object(
79-
Exchange, "publish", return_value=asyncio.sleep(0)
80-
) as mock_publish:
78+
with mock.patch.object(Exchange, "publish") as mock_publish:
8179
decorated_publish = PublishDecorator(
8280
self.tracer, exchange
8381
).decorate(mock_publish)
@@ -101,9 +99,7 @@ def _test_publish_works_with_not_recording_span(self, exchange_type):
10199
mocked_not_recording_span = MagicMock()
102100
mocked_not_recording_span.is_recording.return_value = False
103101
mock_get_publish_span.return_value = mocked_not_recording_span
104-
with mock.patch.object(
105-
Exchange, "publish", return_value=asyncio.sleep(0)
106-
) as mock_publish:
102+
with mock.patch.object(Exchange, "publish") as mock_publish:
107103
with mock.patch(
108104
"opentelemetry.instrumentation.aio_pika.publish_decorator.propagate.inject"
109105
) as mock_inject:
@@ -158,9 +154,7 @@ def _test_publish(self, exchange_type: Type[Exchange]):
158154
with mock.patch.object(
159155
PublishDecorator, "_get_publish_span"
160156
) as mock_get_publish_span:
161-
with mock.patch.object(
162-
Exchange, "publish", return_value=asyncio.sleep(0)
163-
) as mock_publish:
157+
with mock.patch.object(Exchange, "publish") as mock_publish:
164158
decorated_publish = PublishDecorator(
165159
self.tracer, exchange
166160
).decorate(mock_publish)
@@ -184,9 +178,7 @@ def _test_publish_works_with_not_recording_span(self, exchange_type):
184178
mocked_not_recording_span = MagicMock()
185179
mocked_not_recording_span.is_recording.return_value = False
186180
mock_get_publish_span.return_value = mocked_not_recording_span
187-
with mock.patch.object(
188-
Exchange, "publish", return_value=asyncio.sleep(0)
189-
) as mock_publish:
181+
with mock.patch.object(Exchange, "publish") as mock_publish:
190182
with mock.patch(
191183
"opentelemetry.instrumentation.aio_pika.publish_decorator.propagate.inject"
192184
) as mock_inject:

instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_instrumentor_connect(self):
7676
cnx = async_call(aiopg.connect(database="test"))
7777
cursor = async_call(cnx.cursor())
7878
query = "SELECT * FROM test"
79-
cursor.execute(query)
79+
async_call(cursor.execute(query))
8080

8181
spans_list = self.memory_exporter.get_finished_spans()
8282
self.assertEqual(len(spans_list), 1)
@@ -127,7 +127,7 @@ def test_instrumentor_create_pool(self):
127127
cnx = async_call(pool.acquire())
128128
cursor = async_call(cnx.cursor())
129129
query = "SELECT * FROM test"
130-
cursor.execute(query)
130+
async_call(cursor.execute(query))
131131

132132
spans_list = self.memory_exporter.get_finished_spans()
133133
self.assertEqual(len(spans_list), 1)

0 commit comments

Comments
 (0)