MCPcopy Index your code
hub / github.com/python/cpython / test_eq_unregister

Method test_eq_unregister

Lib/test/_test_atexit.py:151–183  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

149 atexit._clear()
150
151 def test_eq_unregister(self):
152 # Issue #112127: callback's __eq__ may call unregister
153 def f1():
154 log.append(1)
155 def f2():
156 log.append(2)
157 def f3():
158 log.append(3)
159
160 class Pred:
161 def __eq__(self, other):
162 nonlocal cnt
163 cnt += 1
164 if cnt == when:
165 atexit.unregister(what)
166 if other is f2:
167 return True
168 return False
169
170 for what, expected in (
171 (f1, [3]),
172 (f2, [3, 1]),
173 (f3, [1]),
174 ):
175 for when in range(1, 4):
176 with self.subTest(what=what.__name__, when=when):
177 cnt = 0
178 log = []
179 for f in (f1, f2, f3):
180 atexit.register(f)
181 atexit.unregister(Pred())
182 atexit._run_exitfuncs()
183 self.assertEqual(log, expected)
184
185
186if __name__ == "__main__":

Callers

nothing calls this directly

Calls 5

PredClass · 0.85
subTestMethod · 0.45
registerMethod · 0.45
unregisterMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected