间谍框架

mockito的Python项目详细描述


mockito是一个最初基于the Java library with the same name的间谍框架。

https://travis-ci.org/kaste/mockito-python.svg?branch=master

安装

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()

阅读文档

http://mockito-python.readthedocs.io/en/latest/

运行测试

pip install pytest
py.test

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在JPA多线程映射中从链接表赋值   java MultiSearchRequest请求返回响应的顺序是否与在SearchRequest中添加的顺序相同?   java如何更改setOnClickListener()中AutoCompleteTextView下拉列表中显示的列表?   java简单邮件列表   java Android代码错误。应用程序意外停止   java显示片段上的数据共享引用   在API 23及以下版本中将图像添加到recycler视图时java崩溃   java web start java_HOME   在Java上通过socket发送ASCII的正确方法是什么?   java双括号初始值设定项和数组   java改变可见性导致我的应用程序崩溃,为什么?   java链表获取retrieveAt方法   RecyclerView中存在多个对象的java错误   java在SpringMVC中定制AcceptedToController方法bean中的绑定请求参数和文件   java使用“权限调度器”添加棉花糖权限