assertEquals vs. assertEqual in python

前端 未结 5 1744
北荒
北荒 2020-12-23 08:21

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

And if there is not, why are there

5条回答
  •  旧巷少年郎
    2020-12-23 09:01

    Good question!

    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.

提交回复
热议问题