间谍框架

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提高机器学习Rest服务性能   java反转字符的字符串顺序,并使用构造函数将其放入LinkedList   继承为什么Java不支持在方法签名中添加“throws”?   执行DDL alter table if exists任务时发生java错误。城市   java在eclipse中使用CREATETXT并打包在jar中   java AES256与3DES 256密钥检测   具有两个相同类型字段的java JPA实体   java Webapp日志记录设置被忽略   java KeyEventDispatcher可以在一个应用程序中工作,但不能在另一个应用程序中工作   带有Swing和OpenJDK的java PinchZoom   未涉及java AspectJ注释切入点(对于任何注释类型)   java如何在FuseBAI中获取日志文件详细信息   java在Linux上将wstring转换为jstring