Python mock paramiko.SSHClient().exec_命令()

Python mock paramiko.SSHClient().exec_命令(),python,mocking,paramiko,Python,Mocking,Paramiko,我需要通过ssh.exec_command()模拟执行一些远程命令 它将元组(stdin、stdout、stderr)作为paramiko.ChanelFile对象返回 因此,我将命令的输出作为字符串(我希望exec_command()返回该字符串)以及如何使用输出字符串创建ChanelFile对象的问题 伪代码: def send_命令(self,cmd) self.client.connect(主机名=self.host, 用户名=self.user, password=self.passw

我需要通过ssh.exec_command()模拟执行一些远程命令 它将元组(stdin、stdout、stderr)作为paramiko.ChanelFile对象返回

因此,我将命令的输出作为字符串(我希望exec_command()返回该字符串)以及如何使用输出字符串创建ChanelFile对象的问题

伪代码:

def send_命令(self,cmd)
self.client.connect(主机名=self.host,
用户名=self.user,
password=self.password,
超时=自身。超时)
stdin,stdout,stderr=self.client.exec_命令(cmd)
返回标准,标准输出,标准输出
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
stdin,stdout,stderr=report.send_命令('ls-la')
resp=stdout.read().strip()
因此,我需要创建stout,以便能够在其上运行read()方法。

请参见 一个魔术师也在这里工作

stdout = mock.MagicMock()
stdout.read().strip.return_value = "file1\nfile2\nfile3\n"
我会成功的