你最喜欢的 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 19:29:36  来源:igfitidea点击:

What is your favorite Python mocking library?

pythonmocking

提问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 John Millikin

Mox, from Google

莫克斯,来自谷歌

回答by ddaa

Mockerfrom Gustavo Niemeyer.

来自古斯塔沃·尼迈耶的嘲笑者

It's not perfect, but it is very powerful and flexible.

它并不完美,但它非常强大和灵活。

回答by John Eikenberry

Dingus, by Gary Bernhardt.

丁格斯,加里·伯恩哈特着。

回答by Carlos Ble

pyDoublesthe test doubles framework for Python, by iExpertos.com. It supports mocks, stubs, spies and matchers, including Hamcrest matchers

pyDouble用于 Python 的测试双打框架,由 iExpertos.com 提供。它支持模拟、存根、间谍和匹配器,包括 Hamcrest 匹配器

回答by gfxmonk

I'm the author for mocktest. I think it's pretty fully featured and easy to use, but I might be biased:

我是模拟测试的作者。我认为它功能齐全且易于使用,但我可能有偏见:

http://gfxmonk.net/dist/doc/mocktest/doc/

http://gfxmonk.net/dist/doc/mocktest/doc/

回答by William Keller

I've used pMockin the past, and didn't mind it, it had pretty decent docs too. However, Foord's Mock as mentioned above is also nice.

我过去使用过pMock,并不介意,它也有相当不错的文档。但是,上面提到的Foord's Mock也不错。