24
24
from opentelemetry .test .test_base import TestBase
25
25
26
26
27
- def async_call (coro , * args , ** kwargs ):
28
- loop = asyncio .get_event_loop ()
29
- return loop .run_until_complete (coro , * args , ** kwargs )
30
-
31
-
32
27
class MockCursor :
33
28
execute = mock .MagicMock (spec = types .MethodType )
34
29
execute .__name__ = "execute"
@@ -117,9 +112,7 @@ async def connect(*args, **kwargs):
117
112
def cursor (self ):
118
113
if self .cursor_factory :
119
114
cur = self .cursor_factory (self )
120
- print ("Returning factory cursor" , cur )
121
115
return cur
122
- print ("Returning MockAsyncCursor" )
123
116
return MockAsyncCursor ()
124
117
125
118
def get_dsn_parameters (self ): # pylint: disable=no-self-use
@@ -238,7 +231,7 @@ async def test_async_connection():
238
231
async with cnx .cursor () as cursor :
239
232
await cursor .execute ("SELECT * FROM test" )
240
233
241
- async_call (test_async_connection ())
234
+ asyncio . run (test_async_connection ())
242
235
spans_list = self .memory_exporter .get_finished_spans ()
243
236
self .assertEqual (len (spans_list ), 1 )
244
237
span = spans_list [0 ]
@@ -251,7 +244,7 @@ async def test_async_connection():
251
244
# check that no spans are generated after uninstrument
252
245
PsycopgInstrumentor ().uninstrument ()
253
246
254
- async_call (test_async_connection ())
247
+ asyncio . run (test_async_connection ())
255
248
256
249
spans_list = self .memory_exporter .get_finished_spans ()
257
250
self .assertEqual (len (spans_list ), 1 )
@@ -265,9 +258,7 @@ async def test_async_connection():
265
258
async with acnx as cnx :
266
259
await cnx .execute ("SELECT * FROM test" )
267
260
268
- import asyncio
269
-
270
- asyncio .run (test_async_connection )
261
+ asyncio .run (test_async_connection ())
271
262
272
263
spans_list = self .memory_exporter .get_finished_spans ()
273
264
self .assertEqual (len (spans_list ), 1 )
0 commit comments