@@ -233,6 +233,7 @@ def test_patch_asyncio(mock_get_running_loop):
233233 Test that the patch_asyncio function will patch the task factory.
234234 """
235235 mock_loop = mock_get_running_loop .return_value
236+ mock_loop .get_task_factory .return_value ._is_sentry_task_factory = False
236237
237238 patch_asyncio ()
238239
@@ -282,6 +283,7 @@ def test_sentry_task_factory_with_factory(mock_get_running_loop):
282283
283284 # The original task factory will be mocked out here, let's retrieve the value for later
284285 orig_task_factory = mock_loop .get_task_factory .return_value
286+ orig_task_factory ._is_sentry_task_factory = False
285287
286288 # Retieve sentry task factory (since it is an inner function within patch_asyncio)
287289 sentry_task_factory = get_sentry_task_factory (mock_get_running_loop )
@@ -344,6 +346,7 @@ def test_sentry_task_factory_context_with_factory(mock_get_running_loop):
344346
345347 # The original task factory will be mocked out here, let's retrieve the value for later
346348 orig_task_factory = mock_loop .get_task_factory .return_value
349+ orig_task_factory ._is_sentry_task_factory = False
347350
348351 # Retieve sentry task factory (since it is an inner function within patch_asyncio)
349352 sentry_task_factory = get_sentry_task_factory (mock_get_running_loop )
@@ -448,18 +451,27 @@ async def test_delayed_enable_integration_with_options(sentry_init, capture_even
448451
449452@minimum_python_38
450453@pytest .mark .asyncio
451- async def test_delayed_enable_enabled_integration (sentry_init ):
454+ async def test_delayed_enable_enabled_integration (sentry_init , uninstall_integration ):
455+ # Ensure asyncio integration is not already installed from previous tests
456+ uninstall_integration ("asyncio" )
457+
452458 integration = AsyncioIntegration ()
453459 sentry_init (integrations = [integration ], traces_sample_rate = 1.0 )
454460
455461 assert "asyncio" in sentry_sdk .get_client ().integrations
456462
463+ # Get the task factory after initial setup - it should be Sentry's
464+ loop = asyncio .get_running_loop ()
465+ task_factory_before = loop .get_task_factory ()
466+ assert getattr (task_factory_before , "_is_sentry_task_factory" , False ) is True
467+
457468 enable_asyncio_integration ()
458469
459470 assert "asyncio" in sentry_sdk .get_client ().integrations
460471
461- # The new asyncio integration should not override the old one
462- assert sentry_sdk .get_client ().integrations ["asyncio" ] == integration
472+ # The task factory should be the same (loop not re-patched)
473+ task_factory_after = loop .get_task_factory ()
474+ assert task_factory_before is task_factory_after
463475
464476
465477@minimum_python_38
0 commit comments