Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Closed
Description
The test case for this is below (it works for Python 3.11 and fails in the current master).
import sysimport unittestclass TestSetLocalTrace(unittest.TestCase): def test_with_branches(self): def tracefunc(frame, event, arg): if frame.f_code.co_name == "func": frame.f_trace = None frame.f_trace = tracefunc line = frame.f_lineno - frame.f_code.co_firstlineno events.append((line, event)) return tracefunc def func(arg=1): N = 1 if arg >= 2: not_reached = 3 else: reached = 5 if arg >= 3: not_reached = 7 else: reached = 9 the_end = 10 EXPECTED_EVENTS = [ (0, 'call'), (1, 'line'), (2, 'line'), (5, 'line'), (6, 'line'), (9, 'line'), (10, 'line'), (10, 'return'), ] events = [] sys.settrace(tracefunc) sys._getframe().f_trace = tracefunc func() self.assertEqual(events, EXPECTED_EVENTS) sys.settrace(None)