您好,我有以下代码;
我正在尝试测试 file_a 中的加载函数;下载是我导入的外部模块中的功能
file_a.py
from foo import download
class Bar()
__init__(self, arg_1):
self.var = arg_1
def load(self):
if self.var == "latest_lib":
download("latest_lib")
我写了这样的测试
test.py
@patch(file_a.download)
def test_download():
import file_a
bar = file_a.Bar("latest_lib")
bar.load()
file_a.download.assert_called()
但似乎 bar 对象没有调用模拟下载,而是调用了导入的下载。我怎样才能解决这个问题并使我的测试通过?