python 函数的调用的时候参数的传递_Python Unittest;如何获取调用函数时传递的参数?...
我試圖做一個單元測試來檢查這個python函數(shù)(dispatch)是否傳遞了正確的參數(shù)來處理\u結(jié)果。在
在dispatch中調(diào)用處理“unu result”的函數(shù)時,有沒有方法“劫持”輸入?yún)?shù)?
我沒有在調(diào)度函數(shù)中修改代碼的權(quán)限。在
以下是單元測試中的want預覽:import maker
from operators import op_morph
import unittest
from unittest.mock import Mock
import cv2
img = cv2.imread("/img_tests/unitTestBaseImage.png")
def my_side_effect(*args, **kwargs):
global img
print(args)
print(kwargs)
if args!=None:
if len(args)>0:
if args[0] == img:
return 0
return 3
else:
return 2
return 1
class TestCalls(unittest.TestCase):
def test_dispatch(self):
global img
makerMock = Mock()
makerMock.deal_with_result.side_effect = my_side_effect
#calling the dispatch function
maker.dispatch(["json_example.json"])
#instead of passing this mock I want to get the real parameters passed
#when the function deal_with_result is called in dispatch.
temp=makerMock.deal_with_result("img")
print("image return code: "+str(temp))
if __name__ == '__main__':
unittest.main(exit=False)
謝謝。在
總結(jié)
以上是生活随笔為你收集整理的python 函数的调用的时候参数的传递_Python Unittest;如何获取调用函数时传递的参数?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: git 常用命令备查
- 下一篇: python为什么忽然火了_为什么Pyt