我用以下方式定义了我的构造函数。在
def __init__(self):
//set some properties
...
self.helperMethod()
def helperMethod(self):
//Do some operation
我想对helper方法进行unittest,但是为了创建执行单元测试的对象,我需要运行__init__
方法。但是,这样做会调用helper方法,这是不可取的,因为这是我需要测试的方法。在
我尝试模拟__init__
方法,但收到的错误是__init__ should return None and not MagicMock
。在
我还尝试用下面的方法模拟helper方法,但是我找不到一种手动恢复模拟方法的方法。MagicMock.reset_模拟()不会这样做。在
^{pr2}$对helper方法进行单元测试的最佳方法是什么?在
您是否尝试捕获
helperMethod
的原始值?在您还可以使用} 装饰器
^{pr2}$mock
库中的^{相关问题 更多 >
编程相关推荐