(self)
| 69 | support.gc_collect() |
| 70 | |
| 71 | def test_refcycle(self): |
| 72 | # A generator caught in a refcycle gets finalized anyway. |
| 73 | old_garbage = gc.garbage[:] |
| 74 | finalized = False |
| 75 | def gen(): |
| 76 | nonlocal finalized |
| 77 | try: |
| 78 | g = yield |
| 79 | yield 1 |
| 80 | finally: |
| 81 | finalized = True |
| 82 | |
| 83 | g = gen() |
| 84 | next(g) |
| 85 | g.send(g) |
| 86 | self.assertGreaterEqual(sys.getrefcount(g), 2) |
| 87 | self.assertFalse(finalized) |
| 88 | del g |
| 89 | support.gc_collect() |
| 90 | self.assertTrue(finalized) |
| 91 | self.assertEqual(gc.garbage, old_garbage) |
| 92 | |
| 93 | def test_lambda_generator(self): |
| 94 | # bpo-23192, gh-119897: Test that a lambda returning a generator behaves |
nothing calls this directly
no test coverage detected