类中的python模拟依赖项

时间:2016-01-20 11:13:06

标签: python mocking

我有类似以下内容,我想测试MailReader查找方法设置模拟传输,但当我尝试仅模拟消息时,我从传输尝试打开连接时收到错误。

class Transport(object):
       def __init__(self, hostname, username, password, ssl):
          # something 
          pass
      def connect(self):
          pass
      def messages(self):
          pass


class MailReader(object):
  def __init__(self, hostname, username, password, ssl):
        super(Mail, self).__init__()
        self.hostname = hostname
        self.username = username
        self.password = password
        self.ssl = ssl
        self.connect()
  def connect(self):
        """
         connect to the email box
        """
        self.connection = Transport(self.hostname, self.username, self.password,
                                self.ssl)
   def find(self, search):
        messages_folder = self.connection.messages()

0 个答案:

没有答案
相关问题