| 175 | |
| 176 | @cpython_only |
| 177 | def test_legacy_finalizer(self): |
| 178 | # A() is uncollectable if it is part of a cycle, make sure it shows up |
| 179 | # in gc.garbage. |
| 180 | @with_tp_del |
| 181 | class A: |
| 182 | def __tp_del__(self): pass |
| 183 | class B: |
| 184 | pass |
| 185 | a = A() |
| 186 | a.a = a |
| 187 | id_a = id(a) |
| 188 | b = B() |
| 189 | b.b = b |
| 190 | gc.collect() |
| 191 | del a |
| 192 | del b |
| 193 | self.assertNotEqual(gc.collect(), 0) |
| 194 | for obj in gc.garbage: |
| 195 | if id(obj) == id_a: |
| 196 | del obj.a |
| 197 | break |
| 198 | else: |
| 199 | self.fail("didn't find obj in garbage (finalizer)") |
| 200 | gc.garbage.remove(obj) |
| 201 | |
| 202 | @cpython_only |
| 203 | def test_legacy_finalizer_newclass(self): |