你最喜欢的 Python 模拟库是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/98053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is your favorite Python mocking library?
提问by Daryl Spitzer
What is your single favorite mocking library for Python?
你最喜欢的 Python 模拟库是什么?
回答by Daryl Spitzer
I've only used one, but I've had good results with Michael Foord's Mock: http://www.voidspace.org.uk/python/mock/.
我只用过一个,但我用 Michael Foord 的 Mock 取得了不错的效果:http://www.voidspace.org.uk/python/mock/ 。
Michael's introduction says it better than I could:
迈克尔的介绍说得比我好:
There are already several Python mocking libraries available, so why another one?
Most mocking libraries follow the 'record -> replay' pattern of mocking. I prefer the 'action -> assertion' pattern, which is more readable and intuitive particularly when working with the Python unittest module.
...
It also provides utility functions / objects to assist with testing, particularly monkey patching.
已经有几个 Python 模拟库可用,那为什么还有一个呢?
大多数模拟库都遵循“记录-> 重放”的模拟模式。我更喜欢“动作-> 断言”模式,它更具可读性和直观性,尤其是在使用 Python unittest 模块时。
...
它还提供实用功能/对象来协助测试,尤其是猴子补丁。
回答by ddaa
回答by Carlos Ble
回答by gfxmonk
I'm the author for mocktest. I think it's pretty fully featured and easy to use, but I might be biased:
我是模拟测试的作者。我认为它功能齐全且易于使用,但我可能有偏见: