python - Python3 unittest 中的 Proxyquire 等效项
问题描述
我正在测试一个看起来像这样的脚本:
import arcpy
Class A:
function go(x, y, z):
arcpy.dothing(y,x,z['attr'])
我想编写一个单元测试python 3.6.6
,传递虚拟参数并验证它们是否正确转换并传递给arcpy.dothing
方法。为此,我在节点中使用了 proxyquire,但在 python 中我无法弄清楚。特别是@patch
似乎不允许捕获输入参数。
解决方案
所以我在经过大量的实验后发现了这一点。这是我最终得到的结果:
import unittest
from a import A
from unittest.mock import patch
class Test_ATest(unittest.TestCase):
@patch('a.arcpy.dothing')
def test_dothing(self, dothing):
d = {"attr": "c"}
obj = A()
obj._go(1,2,d)
dothing.assert_called_with(2,1,'c')
推荐阅读
- azure-active-directory - Azure AD B2C 声明转换
- android - 我什么时候应该更喜欢顶级 const 与伴随对象 const?
- jmeter - jmeter响应时间图中的粒度是什么意思
- c - 有没有办法在 c 中使用套接字编程实现两种 TCP 通信?
- javascript - Javascript - 删除字符串的一部分
- gradle - Gradle:从根项目任务中的子项目读取变量块
- scala - 用“case-like”类型检查来理解
- node.js - 节点js同步for循环
- javascript - 如何在 Angular 中有条件地截断文本元素?
- c - 为什么这会导致分段错误而不会?