繁体   English   中英

Django测试如何检查函数是否未调用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM