diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-27 11:52:20 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-27 11:52:20 (GMT) |
commit | 80f53aa9a0b2af28c9d8052c46b452cccb8e0b41 (patch) | |
tree | 2f1714ab75a7d22f9c719a5890459278d4d581fa /Lib/test/test_asyncio/test_tasks.py | |
parent | bbd96c6f47046e11f47de06550dcd1c816aad71c (diff) | |
download | cpython-80f53aa9a0b2af28c9d8052c46b452cccb8e0b41.zip cpython-80f53aa9a0b2af28c9d8052c46b452cccb8e0b41.tar.gz cpython-80f53aa9a0b2af28c9d8052c46b452cccb8e0b41.tar.bz2 |
asyncio, Tulip issue 137: In debug mode, save traceback where Future, Task and
Handle objects are created. Pass the traceback to call_exception_handler() in
the 'source_traceback' key.
The traceback is truncated to hide internal calls in asyncio, show only the
traceback from user code.
Add tests for the new source_traceback, and a test for the 'Future/Task
exception was never retrieved' log.
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index c5eb92b..54b29ba 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1546,6 +1546,7 @@ class TaskTests(test_utils.TestCase): raise Exception("code never reached") mock_handler = mock.Mock() + self.loop.set_debug(True) self.loop.set_exception_handler(mock_handler) # schedule the task @@ -1560,6 +1561,7 @@ class TaskTests(test_utils.TestCase): # remove the future used in kill_me(), and references to the task del coro.gi_frame.f_locals['future'] coro = None + source_traceback = task._source_traceback task = None # no more reference to kill_me() task: the task is destroyed by the GC @@ -1570,6 +1572,7 @@ class TaskTests(test_utils.TestCase): mock_handler.assert_called_with(self.loop, { 'message': 'Task was destroyed but it is pending!', 'task': mock.ANY, + 'source_traceback': source_traceback, }) mock_handler.reset_mock() @@ -1604,6 +1607,17 @@ class TaskTests(test_utils.TestCase): self.assertRegex(message, re.compile(regex, re.DOTALL)) + def test_task_source_traceback(self): + self.loop.set_debug(True) + + task = asyncio.Task(coroutine_function(), loop=self.loop) + lineno = sys._getframe().f_lineno - 1 + self.assertIsInstance(task._source_traceback, list) + self.assertEqual(task._source_traceback[-1][:3], + (__file__, + lineno, + 'test_task_source_traceback')) + class GatherTestsBase: |