@@ -59,11 +59,20 @@ def my_method(self):
59
59
pass
60
60
61
61
62
+ class BaseTestCase (unittest .TestCase ):
63
+ def setUp (self ):
64
+ self ._thread_key = test .support .threading_setup ()
65
+
66
+ def tearDown (self ):
67
+ test .support .reap_children ()
68
+ test .support .threading_cleanup (* self ._thread_key )
69
+
70
+
62
71
class ExecutorMixin :
63
72
worker_count = 5
64
73
65
74
def setUp (self ):
66
- self . _thread_cleanup = test . support . threading_setup ()
75
+ super (). setUp ()
67
76
68
77
self .t1 = time .time ()
69
78
try :
@@ -81,8 +90,7 @@ def tearDown(self):
81
90
print ("%.2fs" % dt , end = ' ' )
82
91
self .assertLess (dt , 60 , "synchronization issue: test lasted too long" )
83
92
84
- test .support .threading_cleanup (* self ._thread_cleanup )
85
- test .support .reap_children ()
93
+ super ().tearDown ()
86
94
87
95
def _prime_executor (self ):
88
96
# Make sure that the executor is ready to do work before running the
@@ -130,7 +138,7 @@ def test_hang_issue12364(self):
130
138
f .result ()
131
139
132
140
133
- class ThreadPoolShutdownTest (ThreadPoolMixin , ExecutorShutdownTest , unittest . TestCase ):
141
+ class ThreadPoolShutdownTest (ThreadPoolMixin , ExecutorShutdownTest , BaseTestCase ):
134
142
def _prime_executor (self ):
135
143
pass
136
144
@@ -186,7 +194,7 @@ def test_thread_names_default(self):
186
194
t .join ()
187
195
188
196
189
- class ProcessPoolShutdownTest (ProcessPoolMixin , ExecutorShutdownTest , unittest . TestCase ):
197
+ class ProcessPoolShutdownTest (ProcessPoolMixin , ExecutorShutdownTest , BaseTestCase ):
190
198
def _prime_executor (self ):
191
199
pass
192
200
@@ -323,7 +331,7 @@ def test_timeout(self):
323
331
self .assertEqual (set ([future2 ]), pending )
324
332
325
333
326
- class ThreadPoolWaitTests (ThreadPoolMixin , WaitTests , unittest . TestCase ):
334
+ class ThreadPoolWaitTests (ThreadPoolMixin , WaitTests , BaseTestCase ):
327
335
328
336
def test_pending_calls_race (self ):
329
337
# Issue #14406: multi-threaded race condition when waiting on all
@@ -341,7 +349,7 @@ def future_func():
341
349
sys .setswitchinterval (oldswitchinterval )
342
350
343
351
344
- class ProcessPoolWaitTests (ProcessPoolMixin , WaitTests , unittest . TestCase ):
352
+ class ProcessPoolWaitTests (ProcessPoolMixin , WaitTests , BaseTestCase ):
345
353
pass
346
354
347
355
@@ -390,11 +398,11 @@ def test_duplicate_futures(self):
390
398
self .assertEqual (len (completed ), 1 )
391
399
392
400
393
- class ThreadPoolAsCompletedTests (ThreadPoolMixin , AsCompletedTests , unittest . TestCase ):
401
+ class ThreadPoolAsCompletedTests (ThreadPoolMixin , AsCompletedTests , BaseTestCase ):
394
402
pass
395
403
396
404
397
- class ProcessPoolAsCompletedTests (ProcessPoolMixin , AsCompletedTests , unittest . TestCase ):
405
+ class ProcessPoolAsCompletedTests (ProcessPoolMixin , AsCompletedTests , BaseTestCase ):
398
406
pass
399
407
400
408
@@ -465,7 +473,7 @@ def test_max_workers_negative(self):
465
473
self .executor_type (max_workers = number )
466
474
467
475
468
- class ThreadPoolExecutorTest (ThreadPoolMixin , ExecutorTest , unittest . TestCase ):
476
+ class ThreadPoolExecutorTest (ThreadPoolMixin , ExecutorTest , BaseTestCase ):
469
477
def test_map_submits_without_iteration (self ):
470
478
"""Tests verifying issue 11777."""
471
479
finished = []
@@ -482,7 +490,7 @@ def test_default_workers(self):
482
490
(os .cpu_count () or 1 ) * 5 )
483
491
484
492
485
- class ProcessPoolExecutorTest (ProcessPoolMixin , ExecutorTest , unittest . TestCase ):
493
+ class ProcessPoolExecutorTest (ProcessPoolMixin , ExecutorTest , BaseTestCase ):
486
494
def test_killed_child (self ):
487
495
# When a child process is abruptly terminated, the whole pool gets
488
496
# "broken".
@@ -538,7 +546,7 @@ def test_traceback(self):
538
546
f1 .getvalue ())
539
547
540
548
541
- class FutureTests (unittest . TestCase ):
549
+ class FutureTests (BaseTestCase ):
542
550
def test_done_callback_with_result (self ):
543
551
callback_result = None
544
552
def fn (callback_future ):
0 commit comments