def a(): return b() def b(): return c() def c(): return [1,2,3] def matches(frame, list): if list != []: assert list[0][0] == frame[0][0] \ and list[0][1] == frame[0][1] \ and matches(frame[1:], list[1:]) def test_frames(): # Check that objframe() works as expected if it's present. try: from sizer.cpython import utils print "Frames of a() are", utils.objframe(a()) assert matches(utils.objframe(a()), [("test_frame.py", 8), ("test_frame.py", 5), ("test_frame.py", 2), ("test_frame.py", 22)]) except ImportError: print "(failed, no objframe)" pass except AttributeError: print "(failed, no objframe)" pass