title: Pytest running unittest failed with Attribute error
body: <p>I created below function and it's working fine but i am struggling with creating unittest for this function.</p>
  <p>Here's my function:</p>
  <pre><code> def put_config_file_on_device(device, config_backup=None):
      try:
          runn_config = config_backup
          runn_config_database = running_config_from_database(device)
          if runn_config:
              raw_config = runn_config
          else:
              raw_config = runn_config_database
  
          new_file, filename = tempfile.mkstemp()
          os.write(new_file, raw_config.encode('utf-8'))
          ssh = SSHClient()
          ssh.set_missing_host_key_policy(AutoAddPolicy())
          ssh.load_system_host_keys()
          handler = get_handler(device)
          passwd = handler._get_admin_passwords()[1][0]
          ssh.connect(device, username='root', password=get_cred('root'),  
                      look_for_keys=False)
          vendor = str(handler)
          if 'Juniper' in vendor:
              remote_path = f'/var/tmp/{device}.cfg'
          if 'Cisco' in vendor:
              remote_path = f'harddisk:/{device}.cfg'
          scp = SCPClient(ssh.get_transport())
          file_path = f'{filename}'
          scp.put(file_path, remote_path, recursive=False)
          scp.close()
          os.remove(filename)
          return True, f&quot;File store successfully on the device {remote_path}&quot;
      except Exception as err:
          return False, f&quot;Failed to store config on Exception: {err}&quot;
  </code></pre>
  <p>I created below unittest but it's not working. I am getting error while tetsinh the UT.
  i have mocked all the dependencies but not sure what's wrong with the code. I get Attribute error for &lt;class 'paramiko.client.SSHClient.</p>
  <pre><code>    @pytest.mark.parametrize('mock_config_backup', ['someconfig\r\n'])
      @patch(&quot;test.scripts.script.get_cred&quot;)
      @patch(&quot;test.scripts.script.os&quot;)
      @patch(&quot;test.scripts.script.SSHClient.&quot;)
      @patch(&quot;test.scripts.script.SCPClient&quot;)
      @patch(&quot;test.scripts.script.tempfile.mkstemp&quot;)
      @patch(&quot;test.scripts.script.get_device_handler&quot;)
      def test_put_config_file_on_device(mock_handler, mock_temp, mock_os, mock_ssh, mock_scp, mock_cred, mock_config_backup):
          conf = 'someconfig\r\n'
          mock_temp.return_value = new_file, filename
          mock.os.write(new_file, conf.encode('utf-8'))
          remote_path = '/var/tmp/devA.cfg'
          file_path = f'{filename}'
          mock_cred.return_value = 'xyz'
          ret = MagicMock() 
          ret.connect('devA', username='root', password='xyz', look_for_keys=False)
          mock_ssh.return_value = ret
          mock_scp.put = (file_path, remote_path)
          scp.close()
          mock.os.remove(filename)
          status, out = test.scripts.script.put_config_file_on_device(device, mock_config_backup)
          assert status and out == 'File store successfully on the device /var/tmp/devA.cfg'
  </code></pre>
  <p>getting below error.</p>
  <pre><code>    =============================================================================================== FAILURES ===============================================================================================
  ____________________________________________________________________________ test_put_config_file_on_device[someconfig\r\n] ____________________________________________________________________________
  
  args = (), keywargs = {'mock_config_backup': 'someconfig\r\n'}
  
      @wraps(func)
      def patched(*args, **keywargs):
          with self.decoration_helper(patched,
                                      args,
  &gt;                                   keywargs) as (newargs, newkeywargs):
  
  /home/lib/python3.6/site-packages/mock/mock.py:1368: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  /usr/lib/python3.6/contextlib.py:81: in __enter__
      return next(self.gen)
  /home/lib/python3.6/site-packages/mock/mock.py:1334: in decoration_helper
      arg = patching.__enter__()
  /home/lib/python3.6/site-packages/mock/mock.py:1437: in __enter__
      original, local = self.get_original()
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  self = &lt;mock.mock._patch object at 0x7f0e60450240&gt;
  
      def get_original(self):
          target = self.getter()
          name = self.attribute
      
          original = DEFAULT
          local = False
      
          try:
              original = target.__dict__[name]
          except (AttributeError, KeyError):
              original = getattr(target, name, DEFAULT)
          else:
              local = True
      
          if name in _builtins and isinstance(target, ModuleType):
              self.create = True
      
          if not self.create and original is DEFAULT:
              raise AttributeError(
  &gt;               &quot;%s does not have the attribute %r&quot; % (target, name)
              )
  E           AttributeError: &lt;class 'paramiko.client.SSHClient'&gt; does not have the attribute ''
  
  /home/lib/python3.6/site-packages/mock/mock.py:1411: AttributeError
  ===================================================================================== 1 failed, 6 passed in 5.67s
  </code></pre>