views:

1114

answers:

3

Is there a difference between assertEquals and assertEqual in the python unittest.TestCase. And if it is not why are there two functions? Only for convenience?

+1  A: 

I don't find any mention of assertEquals in http://docs.python.org/library/unittest.html. However, when I import TestCase and then do a "help(TestCase)", it's listed. I think it's just a synonym for convenience.

Fred Larson
Yeah, but it badly breaks the "only one obvious way to do it" mantra:-(.
Alex Martelli
@Alex - You'll get no argument from me on that.
Fred Larson
+15  A: 

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.

Jarret Hardie
A: 

I think this was tension between the "only one obvious way to do it" vs. "alias to make the overall code flow semantically". Personally I found I like to read

failIf(some_condition)

over

assertFalse(some_condition)

but liked

assertEqual(a, b)

over the other two (assertEquals(a, b) bothers my sense of grammar).

The "only one obvious way to do it" has taken precedence going forward.

Kathy Van Stone