'Fail if the function is not in the traceback.
Fail the test if the function ``function`` is not at any
of the levels in the traceback object ``traceback``.'

def failUnlessFunctionInTraceback(self, traceback, function, msg=None):

    func_in_traceback = False
    expect_code = function.func_code
    current_traceback = traceback
    while (current_traceback is not None):
        if (expect_code is current_traceback.tb_frame.f_code):
            func_in_traceback = True
            break
        current_traceback = current_traceback.tb_next
    if (not func_in_traceback):
        if (msg is None):
            msg = ('Traceback    did    not    lead    to    original    function    %(function)s' % vars())
        raise self.failureException(msg)
