@@ -38,14 +38,6 @@ async def boom():
3838 1 / 0
3939
4040
41- @pytest .fixture (scope = "session" )
42- def event_loop (request ):
43- """Create an instance of the default event loop for each test case."""
44- loop = asyncio .get_event_loop_policy ().new_event_loop ()
45- yield loop
46- loop .close ()
47-
48-
4941def get_sentry_task_factory (mock_get_running_loop ):
5042 """
5143 Patches (mocked) asyncio and gets the sentry_task_factory.
@@ -58,11 +50,10 @@ def get_sentry_task_factory(mock_get_running_loop):
5850
5951
6052@minimum_python_37
61- @pytest .mark .asyncio
53+ @pytest .mark .asyncio ( loop_scope = "module" )
6254async def test_create_task (
6355 sentry_init ,
6456 capture_events ,
65- event_loop ,
6657):
6758 sentry_init (
6859 traces_sample_rate = 1.0 ,
@@ -76,10 +67,10 @@ async def test_create_task(
7667
7768 with sentry_sdk .start_transaction (name = "test_transaction_for_create_task" ):
7869 with sentry_sdk .start_span (op = "root" , name = "not so important" ):
79- tasks = [event_loop .create_task (foo ()), event_loop .create_task (bar ())]
70+ tasks = [asyncio .create_task (foo ()), asyncio .create_task (bar ())]
8071 await asyncio .wait (tasks , return_when = asyncio .FIRST_EXCEPTION )
8172
82- sentry_sdk .flush ()
73+ sentry_sdk .flush ()
8374
8475 (transaction_event ,) = events
8576
@@ -102,7 +93,7 @@ async def test_create_task(
10293
10394
10495@minimum_python_37
105- @pytest .mark .asyncio
96+ @pytest .mark .asyncio ( loop_scope = "module" )
10697async def test_gather (
10798 sentry_init ,
10899 capture_events ,
@@ -121,7 +112,7 @@ async def test_gather(
121112 with sentry_sdk .start_span (op = "root" , name = "not so important" ):
122113 await asyncio .gather (foo (), bar (), return_exceptions = True )
123114
124- sentry_sdk .flush ()
115+ sentry_sdk .flush ()
125116
126117 (transaction_event ,) = events
127118
@@ -144,11 +135,10 @@ async def test_gather(
144135
145136
146137@minimum_python_37
147- @pytest .mark .asyncio
138+ @pytest .mark .asyncio ( loop_scope = "module" )
148139async def test_exception (
149140 sentry_init ,
150141 capture_events ,
151- event_loop ,
152142):
153143 sentry_init (
154144 traces_sample_rate = 1.0 ,
@@ -162,10 +152,10 @@ async def test_exception(
162152
163153 with sentry_sdk .start_transaction (name = "test_exception" ):
164154 with sentry_sdk .start_span (op = "root" , name = "not so important" ):
165- tasks = [event_loop .create_task (boom ()), event_loop .create_task (bar ())]
155+ tasks = [asyncio .create_task (boom ()), asyncio .create_task (bar ())]
166156 await asyncio .wait (tasks , return_when = asyncio .FIRST_EXCEPTION )
167157
168- sentry_sdk .flush ()
158+ sentry_sdk .flush ()
169159
170160 (error_event , _ ) = events
171161
@@ -178,7 +168,7 @@ async def test_exception(
178168
179169
180170@minimum_python_37
181- @pytest .mark .asyncio
171+ @pytest .mark .asyncio ( loop_scope = "module" )
182172async def test_task_result (sentry_init ):
183173 sentry_init (
184174 integrations = [
@@ -194,7 +184,7 @@ async def add(a, b):
194184
195185
196186@minimum_python_311
197- @pytest .mark .asyncio
187+ @pytest .mark .asyncio ( loop_scope = "module" )
198188async def test_task_with_context (sentry_init ):
199189 """
200190 Integration test to ensure working context parameter in Python 3.11+
@@ -362,11 +352,10 @@ def test_sentry_task_factory_context_with_factory(mock_get_running_loop):
362352
363353
364354@minimum_python_37
365- @pytest .mark .asyncio
355+ @pytest .mark .asyncio ( loop_scope = "module" )
366356async def test_span_origin (
367357 sentry_init ,
368358 capture_events ,
369- event_loop ,
370359):
371360 sentry_init (
372361 integrations = [AsyncioIntegration ()],
@@ -377,11 +366,11 @@ async def test_span_origin(
377366
378367 with sentry_sdk .start_transaction (name = "something" ):
379368 tasks = [
380- event_loop .create_task (foo ()),
369+ asyncio .create_task (foo ()),
381370 ]
382371 await asyncio .wait (tasks , return_when = asyncio .FIRST_EXCEPTION )
383372
384- sentry_sdk .flush ()
373+ sentry_sdk .flush ()
385374
386375 (event ,) = events
387376
0 commit comments