在 Python 中使用模拟时,我遇到了计算路径的问题。
假设我有以下文件
文件1.py
def func1():
return 'X'
Run Code Online (Sandbox Code Playgroud)
文件2.py
from file1 import func1
class ClassA():
def func_that_uses_func1(self):
x = func1()
Run Code Online (Sandbox Code Playgroud)
如何修补 ClassA 上 func1 的使用?我尝试过 @mock.patch('file2.func1'),但出现错误AttributeError: <class 'ClassA'> does not have the attribute 'func1'