Python 使用

Python 使用,python,unit-testing,mocking,patch,Python,Unit Testing,Mocking,Patch,我想为我的所有测试设置一个补丁,并使用patch 即: 现在,这个src.FetchFunction.caching.get\u dynamo是我想要修补的模块的路径 但在我过去使用此模块的地方,我想在测试中进行修补,我做到了: patch('path.to.tested.module.get_dynamo') 现在,如果我做第一个例子,我的get_dynamo没有补丁 但是,如果复制与同一示例相同的路径,则会修补get_dynamo 但这意味着我需要为代码中每次使用get_dynamo进行修

我想为我的所有测试设置一个补丁,并使用
patch

即:

现在,这个
src.FetchFunction.caching.get\u dynamo
是我想要修补的模块的路径

但在我过去使用此模块的地方,我想在测试中进行修补,我做到了:

patch('path.to.tested.module.get_dynamo')
现在,如果我做第一个例子,我的
get_dynamo
没有补丁

但是,如果复制与同一示例相同的路径,则会修补
get_dynamo

但这意味着我需要为代码中每次使用
get_dynamo
进行修补

我的意思是如果我从
file1
so使用它

patch('path.to.file1.get_dynamo')
patch('path.to.file2.get_dynamo')
如果我想在
file2
上打补丁

patch('path.to.file1.get_dynamo')
patch('path.to.file2.get_dynamo')
你知道如何正确设置它吗


谢谢

我相信这个问题以前已经问过并回答过了:在类级别上使用补丁作为装饰程序。谢谢@Theppot已经看到了这一点,但我想问的是,这个模拟文件是否是从多个文件调用的,所以补丁路径是不同的