'Add a function, with arguments, to be called when the test is
completed. Functions added are called on a LIFO basis and are
called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown).'

def addCleanup(self, function, *args, **kwargs):

    self._cleanups.append((function, args, kwargs))
