@@ -230,56 +230,59 @@ def mock_start_new_thread(func, *args, **kwargs):
230230
231231    def  test_process_pool_executor_terminate_kill_workers (self ):
232232        for  function_name  in  ('terminate_workers' , 'kill_workers' ):
233-             manager  =  multiprocessing .Manager ()
234-             q  =  manager .Queue ()
233+             with  self .subTest (function_name = function_name ):
234+                 manager  =  multiprocessing .Manager ()
235+                 q  =  manager .Queue ()
235236
236-             with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
237-                 executor .submit (_put_sleep_put , q )
237+                  with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
238+                      executor .submit (_put_sleep_put , q )
238239
239-                 # We should get started, but not finished since we'll terminate the workers just after 
240-                 self .assertEqual (q .get (timeout = 5 ), 'started' )
240+                      # We should get started, but not finished since we'll terminate the workers just after 
241+                      self .assertEqual (q .get (timeout = 5 ), 'started' )
241242
242-                 worker_process  =  list (executor ._processes .values ())[0 ]
243-                 getattr (executor , function_name )()
244-                 worker_process .join ()
243+                      worker_process  =  list (executor ._processes .values ())[0 ]
244+                      getattr (executor , function_name )()
245+                      worker_process .join ()
245246
246-                 if  function_name  ==  'terminate_workers'  or  sys .platform  ==  'win32' :
247-                     # On windows, kill and terminate both send SIGTERM 
248-                     self .assertEqual (worker_process .exitcode , - signal .SIGTERM )
249-                 elif  function_name  ==  'kill_workers' :
250-                     self .assertEqual (worker_process .exitcode , - signal .SIGKILL )
247+                      if  function_name  ==  'terminate_workers'  or  sys .platform  ==  'win32' :
248+                          # On windows, kill and terminate both send SIGTERM 
249+                          self .assertEqual (worker_process .exitcode , - signal .SIGTERM )
250+                      elif  function_name  ==  'kill_workers' :
251+                          self .assertEqual (worker_process .exitcode , - signal .SIGKILL )
251252
252-                 self .assertRaises (queue .Empty , q .get , timeout = 1 )
253+                      self .assertRaises (queue .Empty , q .get , timeout = 1 )
253254
254255    def  test_process_pool_executor_terminate_kill_workers_dead_workers (self ):
255256        for  function_name  in  ('terminate_workers' , 'kill_workers' ):
256-             with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
257-                 future  =  executor .submit (os ._exit , 1 )
258-                 self .assertRaises (BrokenProcessPool , future .result )
257+             with  self .subTest (function_name = function_name ):
258+                 with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
259+                     future  =  executor .submit (os ._exit , 1 )
260+                     self .assertRaises (BrokenProcessPool , future .result )
259261
260-                 # even though the pool is broken, this shouldn't raise 
261-                 getattr (executor , function_name )()
262+                      # even though the pool is broken, this shouldn't raise 
263+                      getattr (executor , function_name )()
262264
263265    def  test_process_pool_executor_terminate_kill_workers_not_started_yet (self ):
264266        for  function_name  in  ('terminate_workers' , 'kill_workers' ):
267+             with  self .subTest (function_name = function_name ):
268+                 context_with_mocked_process  =  multiprocessing .get_context ()
269+                 with  unittest .mock .patch .object (context_with_mocked_process , 'Process' ) as  mock_process :
270+                     with  futures .ProcessPoolExecutor (max_workers = 1 , mp_context = context_with_mocked_process ) as  executor :
271+                         # The worker has not been started yet, terminate/kill_workers should basically no-op 
272+                         getattr (executor , function_name )()
265273
266-             context_with_mocked_process  =  multiprocessing .get_context ()
267-             with  unittest .mock .patch .object (context_with_mocked_process , 'Process' ) as  mock_process :
268-                 with  futures .ProcessPoolExecutor (max_workers = 1 , mp_context = context_with_mocked_process ) as  executor :
269-                     # The worker has not been started yet, terminate/kill_workers should basically no-op 
270-                     getattr (executor , function_name )()
271- 
272-                 mock_process .return_value .kill .assert_not_called ()
273-                 mock_process .return_value .terminate .assert_not_called ()
274+                     mock_process .return_value .kill .assert_not_called ()
275+                     mock_process .return_value .terminate .assert_not_called ()
274276
275277    def  test_process_pool_executor_terminate_kill_workers_stops_pool (self ):
276278        for  function_name  in  ('terminate_workers' , 'kill_workers' ):
277-             with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
278-                 executor .submit (time .sleep , 0 ).result ()
279+             with  self .subTest (function_name = function_name ):
280+                 with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
281+                     executor .submit (time .sleep , 0 ).result ()
279282
280-                 getattr (executor , function_name )()
283+                      getattr (executor , function_name )()
281284
282-                 self .assertRaises (RuntimeError , executor .submit , time .sleep , 0 )
285+                      self .assertRaises (RuntimeError , executor .submit , time .sleep , 0 )
283286
284287    def  test_process_pool_executor_terminate_workers (self ):
285288        with  futures .ProcessPoolExecutor (max_workers = 1 ) as  executor :
0 commit comments