鼻子和膀胱肿大-有什么(主观)差异,应该让我选择任何一个?

我已经开始从事一个相当大的(多线程) Python 项目,其中包含大量(单元)测试。最重要的问题是,运行应用程序需要一个预设置的环境,该环境由上下文管理器实现。到目前为止,我们使用了单元测试运行程序的补丁版本,它将在这个管理器中运行测试,但是它不允许在不同的测试模块之间切换上下文。

Nose 和 pytest 都支持这样的东西,因为它们在许多粒度上支持 fixture,所以我们正在考虑切换到 nose 或 pytest。这两个库都支持“标记”测试,并且只运行这些标记子集,这也是我们想要做的事情。

我已经浏览了一下 nose 和 pytest 的文档,目前为止,我看到这些库大部分基本上支持相同的功能,只是它们的名称可能不同,或者需要略微不同的语法。此外,我还注意到了可用插件之间的一些小差异(鼻子支持多进程,比如 pytest 似乎不支持)

所以,魔鬼似乎在于细节,这意味着(通常至少)在个人品味方面,我们最好选择最适合我们个人品味的图书馆。

因此,我想要求一个主观的论证,为什么我应该选择鼻子或 pytest,以便选择最适合我们的需求的图书馆/社区组合。

38185 次浏览

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.

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 way less, 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.

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.