Skip to content
Prev Previous commit
Next Next commit
Try harder to break things
  • Loading branch information
markshannon committed Jun 28, 2022
commit ce0d4b5b8d2255ab3e1ae2aaa2ec39e672f84d2a
26 changes: 21 additions & 5 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,41 @@ def f():

def test_handle_frame_object_in_creation(self):
Comment thread
markshannon marked this conversation as resolved.

#Attempt to expose partially constructed frames
#See https://github.com/python/cpython/issues/94262

def cb(*args):
try:
sys._getframe(1)
except ValueError:
pass
inspect.stack()

def gen():
yield 1

thresholds = gc.get_threshold()
gc.callbacks.append(cb)
gc.set_threshold(1, 0, 0)

try:
gen()
finally:
gc.set_threshold(*thresholds)
gc.callbacks.pop()

class Sneaky:
Comment thread
markshannon marked this conversation as resolved.
def __del__(self):
raise KeyboardInterrupt

sneaky = Sneaky()
sneaky._s = Sneaky()
sneaky._s._s = sneaky
del sneaky

gc.set_threshold(1, 0, 0)
try:
gen()
finally:
gc.set_threshold(*thresholds)



class ExceptionTest(unittest.TestCase):
# Tests for the issue #23353: check that the currently handled exception
# is correctly saved/restored in PyEval_EvalFrameEx().
Expand Down