简体   繁体   English

如何检查是否在模拟方法中调用函数?

[英]How do I check if a function is called in a mock method?

AuthUser is a class which contains the delete method. AuthUser是一个包含delete方法的类。 I want to test if the mock delete method calls a function, given the arguments for the method. 我想测试mock delete方法是否在给定方法的参数的情况下调用函数。

@mock.patch.object(AuthUser, 'delete')
@mock.patch('oscadmin.common.oscp.deactivate_user')
def test_delete(self, deactivate_user_mock, delete_mock):
    """Test the delete() method in AuthUser"""
    authUserObject = mock.Mock()
    authUserObject.oscp_id = 4

    """If delete_from_oscp = True && oscp_id isset"""
    delete_mock(self, True, authUserObject, mock.Mock())
    self.assertTrue(authUserObject.oscp_id)
delete_mock.method_expected_to_be_called.assert_called_once_with(args, kwargs)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在python中检查函数是否调用函数? 没有模拟或单元测试。 - How do I check if a function is called in a function or not, in python? No mock or unittest. 如何检查方法是否正在调用函数? - How do I check if a function is being called by a method? 如何使用pytest-mock检查单元测试中是否调用了函数? - How to check if a function was called in a unit test using pytest-mock? 如何模拟从自定义类的自定义方法中调用的 boto3 方法? - How do I mock boto3 methods called from within a custom class' custom method? 如何使用Mox模拟模块函数并允许以几乎任何方式调用它 - How do I use Mox to mock a module function and allow it to be called in almost any way 如何模拟从我的自定义 function 中调用的“csv.DictWriter.writeheader()”? - How do I mock `csv.DictWriter.writeheader()`, which is called from within my custom function? unittest mock 如何模拟被调用的方法 - unittest mock how to mock a method being called 调用使用模拟检查函数时的 PicklingError - PicklingError when using mock to check function is called 使用 Mock 断言未调用函数/方法 - Assert a function/method was not called using Mock 在另一个 function 中调用的模拟 class 方法 - Mock class method that is called within another function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM