【发布时间】:2018-10-18 19:46:32
【问题描述】:
我有一个调用subprocess.check_call() 两次的函数。我想测试他们所有可能的输出。我希望能够将第一个 check_call() 设置为返回 1,将第二个设置为返回 0,并对所有可能的组合都这样做。以下是我到目前为止所拥有的。我不确定如何调整预期返回值
@patch('subprocess.check_call')
def test_hdfs_dir_func(mock_check_call):
for p, d in list(itertools.product([1, 0], repeat=2)):
if p or d:
【问题讨论】:
-
用切换(全局变量)存储以前的状态怎么样
-
一般说明:您不需要强制迭代,只需执行
for p, d in itertools.product([1, 0], repeat=2):
标签: python unit-testing mocking python-unittest