File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
backends/advanced/tests/unit/workers Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -171,20 +171,25 @@ def test_get_consumer_creates_streaming_consumer(self):
171171 assert callable (consumer .start_consuming )
172172 assert callable (consumer .stop )
173173
174- @pytest .mark .asyncio
175- async def test_start_method_runs_worker (self ):
176- """Test that start() class method creates instance and runs it."""
174+ def test_start_method_runs_worker (self ):
175+ """Test that start() class method creates instance and schedules run() via asyncio.run."""
176+ captured_coro = None
177+
177178 with patch .object (DeepgramStreamWorker , "run" , new_callable = AsyncMock ) as mock_run :
178179 with patch ("asyncio.run" ) as mock_asyncio_run :
179- # Simulate script execution
180- mock_asyncio_run . side_effect = lambda coro : asyncio . new_event_loop (). run_until_complete (
181- coro
182- )
180+ def capture_and_close ( coro ):
181+ nonlocal captured_coro
182+ captured_coro = coro
183+ coro . close ( )
183184
184- worker_instance = DeepgramStreamWorker ()
185- await worker_instance .run ()
185+ mock_asyncio_run .side_effect = capture_and_close
186186
187- mock_run .assert_called_once ()
187+ DeepgramStreamWorker .start ()
188+
189+ mock_run .assert_called_once_with ()
190+ mock_asyncio_run .assert_called_once_with (captured_coro )
191+ assert captured_coro is not None
192+ assert asyncio .iscoroutine (captured_coro )
188193
189194
190195@pytest .mark .unit
You can’t perform that action at this time.
0 commit comments