我有一个模块:
Interest
- __init__.py
- simple
- compound
__init__.py:
def add (x, y):
return x + y
我想使用 mock 测试我的模块。为此,我想要对 __ init __.py 中定义的函数进行模拟,并返回模拟值。那么怎么做呢?
我有一个模块:
Interest
- __init__.py
- simple
- compound
__init__.py:
def add (x, y):
return x + y
我想使用 mock 测试我的模块。为此,我想要对 __ init __.py 中定义的函数进行模拟,并返回模拟值。那么怎么做呢?
add
的地方在哪里?你要模拟它的使用,而不是定义它的地方。 - jonrsharpeadd
在__init__
里面还是在类里面?你能展示一下期望的输出吗? - Moon Cheesezdef total() total = add(4,5) 我正在测试total函数,为此我想mock add并返回我的值。 - pjain