assertEquals与python中的assertEqual

2024-09-27 20:17:22 发布

您现在位置:Python中文网/ 问答频道 /正文

python中的assertEqualsassertEqual之间有区别吗?

如果没有,为什么有两个功能?只是为了方便?


Tags: 功能区别assertequalassertequals
3条回答

3.3更新:来自26.3.7.1.1. Deprecated aliases

For historical reasons, some of the TestCase methods had one or more aliases that are now deprecated. The following table lists the correct names along with their deprecated aliases:

Method Name   | Deprecated alias | Deprecated alias
--------------+------------------+-----------------
assertEqual() | failUnlessEqual  | assertEquals
...

好问题!

实际上,在Python 2.6中,assertEqualassertEquals都是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

不仅仅是对于Python 3.x,因为Python 2.7assertEquals也被弃用:

Method Name            | Deprecated alias(es)
_________________________________________________________
assertEqual()          | failUnlessEqual, assertEquals

25.3.7.1.1. Deprecated aliases

相关问题 更多 >

    热门问题