Python Mock:仅用于设置参数的Stub方法

时间:2013-04-28 03:56:20

标签: python mocking mockito

Python mockito允许您在使用某些参数调用时存根方法。

E.g。

from mockito import when

# No wonder that modules have to be imported first
import os.path

# Stub calls
when(os.path).exists("/some/dir").thenReturn(True)
when(os.path).exists("\some]dir").thenRaise(AssertionError("Invalid directory name"))

# Use stubs
assert os.path.exists("/some/dir")
assert os.path.exists("\some]dir") # raises AssertionError: Invalid directory name

https://code.google.com/p/mockito-python/wiki/Stubbing#Modules

与python mock库有什么相同之处?

https://pypi.python.org/pypi/mock

0 个答案:

没有答案