在 python 中 assertEquals 与 assertEqual [英] assertEquals vs. assertEqual in python

查看:96
本文介绍了在 python 中 assertEquals 与 assertEqual的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python unittest.TestCase中的assertEqualsassertEqual有区别吗?

如果没有,为什么会有两个函数?只是为了方便?

解决方案

实际上,在 Python 2.6 中,assertEqualassertEquals 都是 failUnlessEqual<的方便别名/代码>.消息来源这样声明它们:

 # 断言方法的同义词assertEqual = assertEquals = failUnlessEqual

Python 3 中,就您而言,failUnlessEqual 已明确弃用.assertEquals 带有此注释 :-)

<块引用>

断言方法的同义词

复数没有记录.保持这种方式以阻止使用.

不要添加更多.不要删除.

在这些方面经历一个弃用周期会惹恼很多人.

因此,结果似乎是您应该对 Python 2.x 使用任何您喜欢的东西,但对于 Python 3 则倾向于 assertEqual.

Is there a difference between assertEquals and assertEqual in the python unittest.TestCase?

And if there is not, why are there two functions? Only for convenience?

解决方案

Actually, in Python 2.6, both assertEqual and assertEquals are convenience aliases to failUnlessEqual. The source declares them thus:

 # Synonyms for assertion methods
 assertEqual = assertEquals = failUnlessEqual

In Python 3, to your point, failUnlessEqual is explicitly deprecated. assertEquals carries this comment :-)

Synonyms for assertion methods

The plurals are undocumented. Keep them that way to discourage use.

Do not add more. Do not remove.

Going through a deprecation cycle on these would annoy many people.

So, the upshot appears to be that you should use whatever you like for Python 2.x, but tend toward assertEqual for Python 3.

这篇关于在 python 中 assertEquals 与 assertEqual的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆