diff options
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 0838ebf..a5563ba 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2545,19 +2545,26 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase): def test_run_coroutine_threadsafe_task_factory_exception(self): """Test coroutine submission from a tread to an event loop when the task factory raise an exception.""" - # Schedule the target - future = self.loop.run_in_executor( - None, lambda: self.target(advance_coro=True)) - # Set corrupted task factory - self.loop.set_task_factory(lambda loop, coro: wrong_name) + + def task_factory(loop, coro): + raise NameError + + run = self.loop.create_task( + self.loop.run_in_executor( + None, lambda: self.target(advance_coro=True))) + # Set exception handler callback = test_utils.MockCallback() self.loop.set_exception_handler(callback) + + # Set corrupted task factory + self.loop.set_task_factory(task_factory) + # Run event loop with self.assertRaises(NameError) as exc_context: - self.loop.run_until_complete(future) + self.loop.run_until_complete(run) + # Check exceptions - self.assertIn('wrong_name', exc_context.exception.args[0]) self.assertEqual(len(callback.call_args_list), 1) (loop, context), kwargs = callback.call_args self.assertEqual(context['exception'], exc_context.exception) |