我正在尝试使用pytest和pytest模拟运行以下测试
def rm(filename):
helper(filename, 5)
def helper(filename):
pass
def test_unix_fs(mocker):
mocker.patch('module.helper')
rm('file')
helper.assert_called_once_with('file', 5)
但我有个例外AttributeError: 'function' object has no attribute 'assert_called_once_with'
我做错什么了?
在面向对象的情况下:
不能对普通函数执行} 装饰器包装它。例如:
.assert_called_once_with
函数:首先需要用^{或更优雅:
注意,断言将失败,因为您只使用
'file'
调用它。所以一个有效的测试是:编辑:如果函数是在某个模块中定义的,则可以在本地将其包装在decorator中。例如:
相关问题 更多 >
编程相关推荐