@@ -137,7 +137,6 @@ def func():
137137
138138 def test_eq_unregister_clear (self ):
139139 # Issue #112127: callback's __eq__ may call unregister or _clear
140- global cnt
141140 cnt = 0
142141 class Func :
143142 def __init__ (self , action , eq_ret_val ):
@@ -148,26 +147,20 @@ def __call__(self):
148147 return
149148
150149 def __eq__ (self , o ):
151- global cnt
152150 cnt += 1
153151 if cnt == 1 :
154152 self .action (o )
155153 return self .eq_ret_val (o )
156154
157- for action , eq_ret_val in (
158- (lambda o : atexit .unregister (self ), lambda o : NotImplemented ),
159- (lambda o : atexit .unregister (self ), lambda o : True ),
160- (lambda o : atexit .unregister (o ), lambda o : NotImplemented ),
161- (lambda o : atexit .unregister (o ), lambda o : True ),
162- (lambda o : atexit ._clear (), lambda o : NotImplemented ),
163- (lambda o : atexit ._clear (), lambda o : True ),
164- ):
165- cnt = 0
166- f1 = Func (action , eq_ret_val )
167- f2 = Func (action , eq_ret_val )
168- atexit .register (f1 )
169- atexit .register (f2 )
170- atexit ._run_exitfuncs ()
155+ for action in lambda o : atexit .unregister (self ), lambda o : atexit .unregister (o ), lambda o : atexit ._clear ():
156+ for eq_ret_val in NotImplemented , True :
157+ with self .subTest (action = action , eq_ret_val = eq_ret_val ):
158+ cnt = 0
159+ f1 = Func (action , eq_ret_val )
160+ f2 = Func (action , eq_ret_val )
161+ atexit .register (f1 )
162+ atexit .register (f2 )
163+ atexit ._run_exitfuncs ()
171164
172165
173166if __name__ == "__main__" :
0 commit comments