我是编写单元测试的新手,所以请原谅我缺乏知识。我看过以前的帖子,但仍然无法使其正常工作。
我有
def get_bugs():
bugs = []
if ...:
bugs.append(123)
# can be empty
return bugs
def operate(bugs):
for bug in bugs:
do something
def main():
bugs = get_bugs()
if bugs:
operate(bugs)
.... # other methods
-------------------------
# in my test
@mock.patch.object(myutility, "get_bugs", autospec=True, return_value=[])
def test_nobugstooperate():
# logic to ensure myutility.operate was not called because there are no bugs
如何实现从未调用过 mutility.operate 的测试?我不能在上面使用“.call”,因为它不可用。