ssh: fix unittest race condition 09/40709/1
authorRoss Brattain <ross.b.brattain@intel.com>
Wed, 30 Aug 2017 16:35:14 +0000 (09:35 -0700)
committerRoss Brattain <ross.b.brattain@intel.com>
Wed, 30 Aug 2017 16:36:44 +0000 (09:36 -0700)
os.stat is being called multiple times for some reason

we only care that is it called at some point.

======================================================================
FAIL: tests.unit.test_ssh.SSHRunTestCase.test__put_file_sftp
tags: worker-1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jenkins/opnfv/slave_root/workspace/yardstick-verify-master/.tox/py3/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/jenkins/opnfv/slave_root/workspace/yardstick-verify-master/tests/unit/test_ssh.py", line 458, in test__put_file_sftp
    mock_stat.assert_called_once_with("localfile")
  File "/home/jenkins/opnfv/slave_root/workspace/yardstick-verify-master/.tox/py3/lib/python3.5/site-packages/mock/mock.py", line 947, in assert_called_once_with
    raise AssertionError(msg)
AssertionError: Expected 'stat' to be called once. Called 3 times.
Ran 1209 tests in 2.618s
FAILED (id=0, failures=1)
error: testr failed (1)
+ testr failing
======================================================================
FAIL: tests.unit.test_ssh.SSHRunTestCase.test__put_file_sftp
tags: worker-1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jenkins/opnfv/slave_root/workspace/yardstick-verify-master/.tox/py3/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/jenkins/opnfv/slave_root/workspace/yardstick-verify-master/tests/unit/test_ssh.py", line 458, in test__put_file_sftp
    mock_stat.assert_called_once_with("localfile")
  File "/home/jenkins/opnfv/slave_root/workspace/yardstick-verify-master/.tox/py3/lib/python3.5/site-packages/mock/mock.py", line 947, in assert_called_once_with
    raise AssertionError(msg)
AssertionError: Expected 'stat' to be called once. Called 3 times.
Ran 1 tests in 0.110s
FAILED (id=0, failures=1)

Change-Id: I73370996e6e0543419eec8ecbe81be424ec15822
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
tests/unit/test_ssh.py

index 24a9d0c..27ed68c 100644 (file)
@@ -455,8 +455,8 @@ class SSHRunTestCase(unittest.TestCase):
         self.test_client._put_file_sftp("localfile", "remotefile")
 
         sftp.put.assert_called_once_with("localfile", "remotefile")
         self.test_client._put_file_sftp("localfile", "remotefile")
 
         sftp.put.assert_called_once_with("localfile", "remotefile")
-        mock_stat.assert_called_once_with("localfile")
-        sftp.chmod.assert_called_once_with("remotefile", 0o753)
+        mock_stat.assert_any_call("localfile")
+        sftp.chmod.assert_any_call("remotefile", 0o753)
         sftp.__exit__.assert_called_once_with(None, None, None)
 
     def test__put_file_sftp_mode(self):
         sftp.__exit__.assert_called_once_with(None, None, None)
 
     def test__put_file_sftp_mode(self):