all Python 3until 3.12unittestterm
unittest.TestCase.assertEquals
removed
Old names of TestCase assertion methods: assertEquals, failUnless, assert_ and others. Removed in Python 3.12; use assertEqual, assertTrue and friends.
Syntax
self.assertEquals(a, b) # до 3.12
Many assertion methods had two or three names. The extra ones were deprecated in Python 3.1 to 3.5 and removed in 3.12. How to rewrite: failUnless and assert_ become assertTrue; failIf becomes assertFalse; failUnlessEqual and assertEquals become assertEqual; failIfEqual and assertNotEquals become assertNotEqual; failUnlessAlmostEqual and assertAlmostEquals become assertAlmostEqual; failIfAlmostEqual and assertNotAlmostEquals become assertNotAlmostEqual; failUnlessRaises becomes assertRaises; assertRegexpMatches becomes assertRegex; assertRaisesRegexp becomes assertRaisesRegex; assertNotRegexpMatches becomes assertNotRegex. The undocumented assertDictContainsSubset is gone without a replacement: check self.assertLessEqual(sub.items(), d.items()). The teyit tool does the bulk rename.
Examples
# Python 3.12+
import unittest
try:
unittest.TestCase().assertEquals(1, 1)
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.12+
import unittest
tc = unittest.TestCase()
tc.assertEqual(2 + 2, 4)
tc.assertTrue([1])
tc.assertRegex('python', 'th')
tc.assertLessEqual({'a': 1}.items(), {'a': 1, 'b': 2}.items())
print('ok') # → ok
import unittest
tc = unittest.TestCase()
tc.assertEquals(2 + 2, 4)
tc.failUnless([1])
tc.assertRegexpMatches('python', 'th')
print('ok') # → ok
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy