def tearDown(self): d = defer.maybeDeferred(self.conn.transport.loseConnection) d.addCallback(lambda x : self.stopServer()) return d