间谍框架
mockito的Python项目详细描述
mockito是一个最初基于the Java library with the same name的间谍框架。
安装
pip install mockito
快速启动
90%的用例是你想要消除一个副作用。
from mockito import when, mock, unstub when(os.path).exists('/foo').thenReturn(True) # or: import requests # the famous library # you actually want to return a Response-like obj, we'll fake it response = mock({'status_code': 200, 'text': 'Ok'}) when(requests).get(...).thenReturn(response) # use it requests.get('http://google.com/') # clean up unstub()