0
私は、このPython関数(ディスパッチ)が正しいパラメータをdeal_with_resultに渡すかどうかをチェックするためにユニットテストをしようとしています。Python Unittest;関数が呼び出されたときに渡されるパラメータを取得する方法は?
ディスパッチで関数deal_with_resultが呼び出されたときに、入力パラメータを「ハイジャック」する方法はありますか?
私はディスパッチ機能のコードを変更する権利を持っていません。ここで
は、私は私のユニットテストに旺旺のプレビューです:
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)
ありがとうございました。