【发布时间】:2022-01-15 18:26:02
【问题描述】:
假设我的根目录中有文件main.py 和common.py。这些代表我暂时不想接触的第三方模块。假设我还有一个 test.py 文件,我想用它来测试 main.py。
common.py 包含以下内容:
def hello():
print("hello")
main.py 包含以下内容:
from common import hello
hello()
有没有办法对test.py 中的hello 函数进行猴子补丁,以便导入main.py 将使用模拟函数?例如,我想给hello打补丁以打印出goodbye。
【问题讨论】:
标签: python mocking monkeypatching