1、基础的打桩方式
# stub.py
import mock
import need
def myfunc():
pass
need.func = mock.MagicMock(side_effect=myfunc)
# need.py
def func():
pass
# main.py
import need
import stub
need.func()
2、对装饰器包裹的函数打桩
同上,依旧对原函数打桩
2023-10-22 20:31:16
1、基础的打桩方式
# stub.py
import mock
import need
def myfunc():
pass
need.func = mock.MagicMock(side_effect=myfunc)
# need.py
def func():
pass
# main.py
import need
import stub
need.func()
2、对装饰器包裹的函数打桩
同上,依旧对原函数打桩