python unittest.TestCase
中的assertEquals
和assertEqual
有区别吗?
如果没有,为什么有两个函数?只是为了方便?
最佳答案
实际上,在 Python 2.6 中,assertEqual
和 assertEquals
都是 failUnlessEqual
的方便别名。来源这样声明它们:
# Synonyms for assertion methods
assertEqual = assertEquals = failUnlessEqual
在 Python 3 ,就您而言, failUnlessEqual
已明确弃用。 assertEquals
带有此注释:-)
# 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.
因此,结果似乎是您应该在 Python 2.x 中使用您喜欢的任何东西,但在 Python 3 中倾向于使用 assertEqual
。
https://stackoverflow.com/questions/930995/