'If an added callable returns a L{Deferred}, then the test should wait
until that L{Deferred} has fired before running the next cleanup
method.'

def test_addCleanupWaitsForDeferreds(self):

    def cleanup(message):
        d = defer.Deferred()
        reactor.callLater(0, d.callback, message)
        return d.addCallback(self.test.append)
    self.test.addCleanup(self.test.append, 'foo')
    self.test.addCleanup(cleanup, 'bar')
    self.test.run(self.result)
    self.assertEqual(['setUp', 'runTest', 'bar', 'foo', 'tearDown'], self.test.log)
