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

Method test_refcycle

Lib/test/test_generators.py:71–91  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

assertGreaterEqualMethod · 0.80
assertFalseMethod · 0.80
assertTrueMethod · 0.80
genFunction · 0.70
sendMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected