[英]How to check if a function was called in a unit test using pytest-mock?
[英]Django test how to check if function was Not called
我想编写一个测试以检查未调用特定功能。 以下是我的代码的伪示例:
码
TestFunctionA():
if a > b:
TestFunctionB()
为了检查它是否被称为我做下面的工作
with mock.patch('TestFunctionB') as mock_TestFunctionB:
TestFunctionA()
mock_TestFunctionB.assert_called_once_with()
如果我想检查是否未调用功能TestFunctionB,我尝试了以下操作,但无法正常工作
with mock.patch('TestFunctionB') as mock_TestFunctionB:
TestFunctionA()
assert not mock_TestFunctionB.assert_called_once_with()
有专门用于此的方法。
mock_TestFunctionB.assert_not_called()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.