def httpd(): server_address = ('127.0.0.1', 8001) httpd = HTTPServer(server_address, MPCHttpHandler) httpd.comm = MagicMock() yield httpd httpd.shutdown() httpd.server_close()