Python 鼻子与 pytest - 应该让我选择的(主观)差异是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22856638/
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
nose vs pytest - what are the (subjective) differences that should make me pick either?
提问by Jakob van Bethlehem
I've started working on a rather big (multithreaded) Python project, with loads of (unit)tests. The most important problem there is that running the application requires a preset environment, which is implemented by a context manager. So far we made use of a patched version of the unit test runner that would run the tests inside this manager, but that doesn't allow switching context between different test modules.
我已经开始研究一个相当大的(多线程)Python 项目,其中包含大量(单元)测试。最重要的问题是运行应用程序需要一个由上下文管理器实现的预设环境。到目前为止,我们使用了单元测试运行器的补丁版本,它可以在这个管理器中运行测试,但这不允许在不同测试模块之间切换上下文。
Both nose and pytest do support such a thing because they support fixtures at many granularities, so we're looking into switching to nose or pytest. Both these libraries would also support 'tagging' tests and run only these tagged subsets, which is something we also would like to do.
鼻子和 pytest 都支持这样的事情,因为它们支持许多粒度的装置,所以我们正在考虑切换到鼻子或 pytest。这两个库也将支持“标记”测试并仅运行这些标记的子集,这也是我们想做的事情。
I have been looking through the documentation of both nose and pytest a bit, and as far as I can see the bigger part of those libraries essentially support the same functionality, except that it may be named differently, or require slightly different syntax. Also, I noted some small differences in the available plugins (nose has multiprocess-support, pytest doesn't seem to for instance)
我一直在浏览nose 和pytest 的文档,据我所知,这些库的大部分基本上支持相同的功能,只是它的命名可能不同,或者需要的语法略有不同。另外,我注意到可用插件中的一些小差异(鼻子具有多进程支持,例如 pytest 似乎没有)
So it seems, the devil is in the detail, which means (often at least) in personal taste and we better go with the library that fits our personal taste best.
所以看起来,问题在于细节,这意味着(通常至少)在个人品味上,我们最好选择最适合我们个人品味的图书馆。
So I'd to ask for a subjective argumentation why I should be going with nose or pytest in order to choose the library/community combo that best fits our needs.
所以我会要求主观论证为什么我应该使用鼻子或 pytest 来选择最适合我们需求的图书馆/社区组合。
采纳答案by Eevee
I used to use Nose because it was the default with Pylons. I didn't like it at all. It had configuration tendrils in multiple places, virtually everything seemed to be done with an underdocumented plugin which made it all even more indirect and confusing, and because it did unittest tests by default, it regularly broke with Unicode tracebacks, hiding the sources of errors.
我曾经使用 Nose,因为它是 Pylons 的默认设置。我根本不喜欢它。它在多个地方都有配置卷须,几乎所有事情似乎都是用一个文档不足的插件完成的,这使得它更加间接和混乱,并且因为它默认进行单元测试,所以它经常与 Unicode 回溯中断,隐藏错误的来源。
I've been pretty happy with py.test the last couple years. Being able to just write a test with assert
out of the box makes me hate writing tests wayless, and hacking whatever I need atop the core has been pretty easy. Rather than a fixed plugin interface it just has piles of hooks, and pretty understandable source code should you need to dig further. I even wrote an adapter for running Testify tests under py.test, and had more trouble with Testify than with py.test.
在过去的几年里,我对 py.test 非常满意。如果能够只写一个测试assert
开箱让我讨厌写作的测试方法较少,和黑客无论我需要上盖的核心一直是很容易的。它不是一个固定的插件接口,它只有成堆的钩子,如果你需要进一步挖掘,源代码很容易理解。我什至写了一个适配器来在 py.test 下运行 Testify 测试,并且 Testify 比 py.test 有更多的麻烦。
That said, I hear nose has plugins for classless tests and assert introspection nowadays, so you'll probably do fine with either. I still feel like I can hit the ground running with py.test, though, and I can understand what's going on when it breaks.
也就是说,我听说鼻子现在有用于无类测试的插件并断言自省,所以你可能会做得很好。不过,我仍然觉得我可以用 py.test 开始运行,而且我可以理解当它中断时发生了什么。