diff -r d1ef91025d70 Lib/test/test_concurrent_futures.py --- a/Lib/test/test_concurrent_futures.py Mon Jan 14 19:27:36 2013 +0200 +++ b/Lib/test/test_concurrent_futures.py Thu Jan 24 14:25:32 2013 -0600 @@ -1,13 +1,14 @@ import test.support -# Skip tests if _multiprocessing wasn't built. -test.support.import_module('_multiprocessing') -# Skip tests if sem_open implementation is broken. -test.support.import_module('multiprocessing.synchronize') -# import threading after _multiprocessing to raise a more revelant error -# message: "No module named _multiprocessing". _multiprocessing is not compiled -# without thread support. -test.support.import_module('threading') +def setUpModule(): + # Skip tests if _multiprocessing wasn't built. + test.support.import_module('_multiprocessing') + # Skip tests if sem_open implementation is broken. + test.support.import_module('multiprocessing.synchronize') + # import threading after _multiprocessing to raise a more revelant error + # message: "No module named _multiprocessing". _multiprocessing is not + # compiled without thread support. + test.support.import_module('threading') from test.script_helper import assert_python_ok @@ -94,7 +95,7 @@ executor_type = futures.ProcessPoolExecutor -class ExecutorShutdownTest(unittest.TestCase): +class ExecutorShutdownTest: def test_run_after_shutdown(self): self.executor.shutdown() self.assertRaises(RuntimeError, @@ -122,7 +123,9 @@ f.result() -class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest): +class ThreadPoolShutdownTest(ThreadPoolMixin, + ExecutorShutdownTest, + unittest.TestCase): def _prime_executor(self): pass @@ -154,7 +157,9 @@ t.join() -class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest): +class ProcessPoolShutdownTest(ProcessPoolMixin, + ExecutorShutdownTest, + unittest.TestCase): def _prime_executor(self): pass @@ -190,8 +195,7 @@ p.join() -class WaitTests(unittest.TestCase): - +class WaitTests: def test_first_completed(self): future1 = self.executor.submit(mul, 21, 2) future2 = self.executor.submit(time.sleep, 1.5) @@ -291,8 +295,7 @@ self.assertEqual(set([future2]), pending) -class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests): - +class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, unittest.TestCase): def test_pending_calls_race(self): # Issue #14406: multi-threaded race condition when waiting on all # futures. @@ -309,11 +312,11 @@ sys.setswitchinterval(oldswitchinterval) -class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests): +class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests, unittest.TestCase): pass -class AsCompletedTests(unittest.TestCase): +class AsCompletedTests: # TODO(brian@sweetapp.com): Should have a test with a non-zero timeout. def test_no_timeout(self): future1 = self.executor.submit(mul, 2, 21) @@ -351,15 +354,19 @@ completed_futures) -class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests): +class ThreadPoolAsCompletedTests(ThreadPoolMixin, + AsCompletedTests, + unittest.TestCase): pass -class ProcessPoolAsCompletedTests(ProcessPoolMixin, AsCompletedTests): +class ProcessPoolAsCompletedTests(ProcessPoolMixin, + AsCompletedTests, + unittest.TestCase): pass -class ExecutorTest(unittest.TestCase): +class ExecutorTest: # Executor.shutdown() and context manager usage is tested by # ExecutorShutdownTest. def test_submit(self): @@ -419,7 +426,9 @@ "Stale reference not collected within timeout.") -class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest): +class ThreadPoolExecutorTest(ThreadPoolMixin, + ExecutorTest, + unittest.TestCase): def test_map_submits_without_iteration(self): """Tests verifying issue 11777.""" finished = [] @@ -431,7 +440,9 @@ self.assertCountEqual(finished, range(10)) -class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest): +class ProcessPoolExecutorTest(ProcessPoolMixin, + ExecutorTest, + unittest.TestCase): def test_killed_child(self): # When a child process is abruptly terminated, the whole pool gets # "broken". @@ -667,21 +678,16 @@ self.assertTrue(isinstance(f1.exception(timeout=5), OSError)) -@test.support.reap_threads -def test_main(): - try: - test.support.run_unittest(ProcessPoolExecutorTest, - ThreadPoolExecutorTest, - ProcessPoolWaitTests, - ThreadPoolWaitTests, - ProcessPoolAsCompletedTests, - ThreadPoolAsCompletedTests, - FutureTests, - ProcessPoolShutdownTest, - ThreadPoolShutdownTest, - ) - finally: - test.support.reap_children() +class ReapedSuite(unittest.TestSuite): + @test.support.reap_threads + def run(self, result): + try: + return super(unittest.TestSuite, self).run(result) + finally: + test.support.reap_children() + +def load_tests(loader, tests, pattern): + return ReapedSuite(tests) if __name__ == "__main__": - test_main() + unittest.main()