在 python 中 assertEquals 与 assertEqual [英] assertEquals vs. assertEqual in python
问题描述
python unittest.TestCase
中的assertEquals
和assertEqual
有区别吗?
如果没有,为什么会有两个函数?只是为了方便?
实际上,在 Python 2.6 中,assertEqual
和 assertEquals
都是 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屋!