Avoid deprecated TestCase method aliases

Don't use deprecated TestCase assertions like self.assertEquals. Use their modern counterpart instead like self.assertEqual.

For historical reasons, some TestCase methods had one or more aliases that are now deprecated.

Use the standardised assertions so the code is simpler, easier to read, and more future-proof (because an implication of deprecation is it will eventually be removed).

DeprecatedStandardised
assertEqualsassertEqual
failUnlessEqualassertEqual
failIfEqualassertNotEqual
assertNotEqualsassertNotEqual
failUnlessassertTrue
assert_assertTrue
failIfassertFalse
failUnlessRaisesassertRaises
failUnlessAlmostEqualassertAlmostEqual
assertAlmostEqualsassertAlmostEqual
assertNotAlmostEqualsassertNotAlmostEqual
failIfAlmostEqualassertNotAlmostEqual
assertRegexpMatchesassertRegex
assertNotRegexpMatchesassertNotRegex
assertRaisesRegexpassertRaisesRegex

If our GitHub code review bot spots this issue in your pull request it gives this advice:

code-review-doctorbotsuggested changes just now
tests.py
1
+
class TestFeature(unittest.TestCase):
2
+
    def test_feature(self):
3
+
        self.assertEquals(int('1'), 1)

Don't use deprecated TestCase assertions like self.assertEquals. Use their modern counterpart instead like self.assertEqual.

Read more
Suggested changes
-
        self.assertEquals(int('1'), 1)
+
        self.assertEqual(int('1'), 1)
Commit suggestion
Update tests.py

Instantly check if you have this issue for free

    Works with tools you use

    Read about how it works.