summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_concurrent_futures.py
diff options
context:
space:
mode:
authorBrian Quinlan <brian@sweetapp.com>2010-10-06 13:05:45 (GMT)
committerBrian Quinlan <brian@sweetapp.com>2010-10-06 13:05:45 (GMT)
commit1e2ae4f054c20f54238997987416dcff0f3b0f3a (patch)
tree3212f91cab82c64da9485eed6bcd4e9b143da0c2 /Lib/test/test_concurrent_futures.py
parent5ad8ed5f26d5d511c3c058c16229e35cb43ba29f (diff)
downloadcpython-1e2ae4f054c20f54238997987416dcff0f3b0f3a.zip
cpython-1e2ae4f054c20f54238997987416dcff0f3b0f3a.tar.gz
cpython-1e2ae4f054c20f54238997987416dcff0f3b0f3a.tar.bz2
Fixes 9903: test_concurrent_futures writes on stderr
Diffstat (limited to 'Lib/test/test_concurrent_futures.py')
-rw-r--r--Lib/test/test_concurrent_futures.py50
1 files changed, 31 insertions, 19 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py
index c36f123..6427368 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -9,6 +9,8 @@ test.support.import_module('multiprocessing.synchronize')
# without thread support.
test.support.import_module('threading')
+import io
+import logging
import multiprocessing
import sys
import threading
@@ -21,7 +23,8 @@ if sys.platform.startswith('win'):
from concurrent import futures
from concurrent.futures._base import (
- PENDING, RUNNING, CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED, Future, wait)
+ PENDING, RUNNING, CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED, Future,
+ LOGGER, STDERR_HANDLER, wait)
import concurrent.futures.process
def create_future(state=PENDING, exception=None, result=None):
@@ -617,24 +620,33 @@ class FutureTests(unittest.TestCase):
self.assertTrue(was_cancelled)
def test_done_callback_raises(self):
- raising_was_called = False
- fn_was_called = False
-
- def raising_fn(callback_future):
- nonlocal raising_was_called
- raising_was_called = True
- raise Exception('doh!')
-
- def fn(callback_future):
- nonlocal fn_was_called
- fn_was_called = True
-
- f = Future()
- f.add_done_callback(raising_fn)
- f.add_done_callback(fn)
- f.set_result(5)
- self.assertTrue(raising_was_called)
- self.assertTrue(fn_was_called)
+ LOGGER.removeHandler(STDERR_HANDLER)
+ logging_stream = io.StringIO()
+ handler = logging.StreamHandler(logging_stream)
+ LOGGER.addHandler(handler)
+ try:
+ raising_was_called = False
+ fn_was_called = False
+
+ def raising_fn(callback_future):
+ nonlocal raising_was_called
+ raising_was_called = True
+ raise Exception('doh!')
+
+ def fn(callback_future):
+ nonlocal fn_was_called
+ fn_was_called = True
+
+ f = Future()
+ f.add_done_callback(raising_fn)
+ f.add_done_callback(fn)
+ f.set_result(5)
+ self.assertTrue(raising_was_called)
+ self.assertTrue(fn_was_called)
+ self.assertIn('Exception: doh!', logging_stream.getvalue())
+ finally:
+ LOGGER.removeHandler(handler)
+ LOGGER.addHandler(STDERR_HANDLER)
def test_done_callback_already_successful(self):
callback_result = None