admin管理员组文章数量:1313169
Iam writing pytest for method -
def upload(type="", local_file=None, remote_file=None,
target_config=None, verify_existence=True,throw_on_error=False):
if not local_file or not target_config:
return None
logger = default_logger
target_path = remote_file if remote_file else local_file
pdir = os.path.dirname(target_path)
cip = getattr(
target_config, "address", None) or target_config.cip
if verify_existence:
target_check = "test -f '%s'" % target_path
_, _, ret = ssh(ip=cip,command=[target_check],throw_on_error=False)
if ret == 0:
message = ("Target file %s(%s) already exists. "
"Skipping upload" % (cip, target_path))
logger.info(message)
return local_file
else:
message = ("Target file %s(%s) not present. Uploading file"
% (cip, target_path))
logger.info(message)
for _ in range(10):
_, _, ret = ssh(ip=cip, command=["mkdir", "-p", pdir],
throw_on_error=False)
_, _, ret = scp(
ip=cip,target_path=target_path,files=[local_file],
log_on_error=True, throw_on_error=False,
timeout=None)
if ret == 0:
return local_file
else:
message = ("Failed to upload %s(%s) to %s:%s" % (type,
local_file, cip, target_path))
logger.error(message)
if throw_on_error:
raise Exception(message)
My test case - -
def test_upload(self):
default_logger = self.mock.CreateMockAnything()
pdir ="tmp/sample_path"
local_file = "tmp/local_path"
cip = "10.1.1.1"
verify_existence=True
objectName.ssh(cip, command=["test", "-f", 'tmp/sample_path'], throw_on_error=False).AndReturn(("", "",0))
self.mock.ReplayAll()
result = objectName.upload( local_file= "tmp/local_path" , verify_existence=True)
print(result)
self.mock.VerifyAll()
But it fails with :test_upload_local_file - mox3.mox.ExpectedMethodCallsError: Verify: Expected methods never called: and also return None as result, I want local_file as my output. What is wrong in my test case
本文标签: pythonPytest not executing mock statementStack Overflow
版权声明:本文标题:python - Pytest not executing mock statement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741927610a2405382.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论