GH-100126: Skip incomplete frames in more places (GH-100613)

This commit is contained in:
Brandt Bucher 2023-01-09 12:20:04 -08:00 committed by GitHub
parent 2e80c2a976
commit 61762b9387
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 62 additions and 46 deletions

View file

@ -1,4 +1,5 @@
import gc
import operator
import re
import sys
import textwrap
@ -372,6 +373,26 @@ class TestIncompleteFrameAreInvisible(unittest.TestCase):
)
sneaky_frame_object = sneaky_frame_object.f_back
def test_entry_frames_are_invisible_during_teardown(self):
class C:
"""A weakref'able class."""
def f():
"""Try to find globals and locals as this frame is being cleared."""
ref = C()
# Ignore the fact that exec(C()) is a nonsense callback. We're only
# using exec here because it tries to access the current frame's
# globals and locals. If it's trying to get those from a shim frame,
# we'll crash before raising:
return weakref.ref(ref, exec)
with support.catch_unraisable_exception() as catcher:
# Call from C, so there is a shim frame directly above f:
weak = operator.call(f) # BOOM!
# Cool, we didn't crash. Check that the callback actually happened:
self.assertIs(catcher.unraisable.exc_type, TypeError)
self.assertIsNone(weak())
@unittest.skipIf(_testcapi is None, 'need _testcapi')
class TestCAPI(unittest.TestCase):
def getframe(self):