Unittest Mock-断言不调用模拟对象

时间:2019-08-04 23:43:36

标签: python unit-testing python-unittest

我是第一次使用Python进行单元测试和模拟。我想断言不调用模拟程序。

    def test_check_is_available_all_day(self):
        create_not_on_leave = Mock()
        delete_not_on_leave = Mock()
        create_is_not_available = Mock()
        for idx, row in self.employee.iterrows():
            if row['all_day'] == 1:
                if row['is_available'] == 1:
                    create_not_on_leave()
                    create_not_on_leave.assert_called()
                elif row['is_available'] == 0:
                    delete_not_on_leave()
                    create_is_not_available()

我如何断言delete_not_on_leave()没有被调用。我尝试过assert delete_not_on_leave.assert_called() == False,但这是错误的。

1 个答案:

答案 0 :(得分:0)

使用:self.assertEqual(create_not_on_leave.call_count, 0)

相关问题