all Python 3unittestfunction
unittest.TestCase.assertEqual()
checks
Assert that two values are equal (==), printing both on failure; the basic TestCase assertion most checks are built on.
Syntax
self.assertEqual(first, second, msg=None)
The check is plain ==, so 1, 1.0 and True all compare equal and a type mix-up slips through: use assertIs for identity and assertAlmostEqual for floats, otherwise rounding error will trip the test. When both arguments share a type, unittest dispatches to a type-aware comparator (lists, dicts, multi-line strings) and prints a readable diff, truncated at self.maxDiff — set it to None to see everything.
Examples
import unittest
class Tests(unittest.TestCase):
def test_equal(self):
self.assertEqual(2 ** 3, 8)
self.assertNotEqual(1, 2)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy