【发布时间】:2017-01-06 05:27:46
【问题描述】:
我对 python 还很陌生。我正在尝试使用模拟来编写单元测试。这是代码的模式。
# mod3.py
import mod1.class1
import mod2.class2
d = {
"c1": class1
"c2": class2
}
def func1(c, v):
cl = d[c]
o = cl().meth1(v)
return o
我想为 func1 写一个单元测试。
def test_func1(c, v):
c, v = mock.Mock(), mock.Mock()
r = mod3.func1(c,v)
e = {"key1": "value1"}
#want to check if the ret val is as expected
我如何使用 mock 来模拟 cl().meth1(v)
【问题讨论】:
-
谢谢!但我不认为这是mocking functions using python mock的重复