Skip to content

Commit 075c49f

Browse files
Address code review comments in atexit tests
1 parent 8e6d5c6 commit 075c49f

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

Lib/test/_test_atexit.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

173166
if __name__ == "__main__":

0 commit comments

Comments
 (0)