在keyboard.py里面有两个功能:
def get_keys(keyList,timeStamped): return event.getKeys(keyList=keyList,timeStamped=timeStamped)def wait_keys(keyList,timeStamped): return event.waitKeys(keyList=keyList,timeStamped=timeStamped)
现在,我在test.py中的测试函数如下所示:
@mock.patch('keyboard.wait_keys') @mock.patch('keyboard.get_keys') def test_2(self,mock_waitKeys,mock_getKeys): mock_waitKeys.return_value = [['wait_keys!',0.1]] mock_getKeys.return_value = [['get_keys!',0.1]] run_blocks(trials,noise,win,expInfo,incorrect,tone1,tone2,experiment_details,allPoints,32,60)
正如您所看到的,我正在尝试将两个模拟返回值放在适当的位置.
然而,他们的影响似乎是倒置的!
当我在交互式控制台中调用它们而在断点处停止时(或在正常调用时检查值),两个模拟函数返回彼此的假返回值!
从控制台:
get_keys()Out[2]: [['wait_keys!',0.1]]wait_keys()Out[3]: [['get_keys!',0.1]]
我是否误解了传递给测试函数的模拟参数的顺序?
这可能与修补keyboard.get_keys而不是test.get_keys有关吗?
谢谢!
路易丝
总结Note When you nest patch decorators the mocks are passed in to the decorated function in the same order they applIEd (the normal python order that decorators are applIEd). This means from the bottom up,so in the example above the mock for module.Classname1 is passed in first.
以上是内存溢出为你收集整理的为什么我的Python模拟补丁以错误的顺序出现?全部内容,希望文章能够帮你解决为什么我的Python模拟补丁以错误的顺序出现?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)