Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中模拟修补程序ctypes.windlel?_Python_Unit Testing_Mocking - Fatal编程技术网

如何在python中模拟修补程序ctypes.windlel?

如何在python中模拟修补程序ctypes.windlel?,python,unit-testing,mocking,Python,Unit Testing,Mocking,我正在尝试编写检查函数参数的单元测试: def test_my_function(): my_function = mock.patch('mymodule.myclass.myfuction') 在mymodule中,我的功能如下所示: from ctypes import POINTER, WinDLL, c_int, cast, pointer, byref class myclass: def myfunction(): # some logic 测

我正在尝试编写检查函数参数的单元测试:

def test_my_function():
    my_function = mock.patch('mymodule.myclass.myfuction')
在mymodule中,我的功能如下所示:

from ctypes import POINTER, WinDLL, c_int, cast, pointer, byref

class myclass:
    def myfunction():
        # some logic
测试失败,并显示错误消息:

ImportError:无法导入名称Windell

因此,我试图在测试中模拟patch
ctypes.windell

mocker.patch('ctypes.WinDLL')
my_function = mock.patch('mymodule.myclass.myfuction')
出现错误:

AttributeError:没有“windell”属性

我无法模拟修补程序Windl,因为如果客户端使用Windows,则
ctypes
定义
Windl
。我的操作系统是Linux


有可能解决这个问题吗?

我自己也找到了解决办法。默认情况下,
mocker.patch
仅修补定义的属性。可以模拟不存在的属性,传递参数
create=True

mocker.patch('ctypes.windl',create=True)