assertEqual is a unittest.TestCase assertion that compares an actual value with an expected value. If the values are equal, the test passes; otherwise, unittest reports an AssertionError. section 13.3.2 section 13.5
Compare a created object with the expected result
class TestTaskCreation(unittest.TestCase): def test_create_task(self): task_text = "Laundry,3" created_task = create_task(task_text) self.assertEqual( created_task.__dict__, Task("Laundry", 3).__dict__ ) Here, assertEqual compares the created task's attribute dictionary with the expected task's dictionary. A successful run reports OK. section 13.3.2
Listing 13.5 Testing a function using TestCase (test_task_func.py)
from task_func import Task, create_task #1
import unittest #2
class TestTaskCreation(unittest.TestCase): #3
def test_create_task(self):
task_text = "Laundry,3"
created_task = create_task(task_text) #4
self.assertEqual(created_task.__dict__,
Task("Laundry", 3).__dict__)
if __name__ == "__main__":
unittest.main()
Use the complete listing to see assertEqual inside a TestCase subclass, alongside test discovery and unittest.main(). section 13.3.2
Use assertEqual for expected-versus-generated results, including function returns and method output. When it fails, compare the displayed values and correct either the implementation or the expected value. section 13.3.2 section 13.4.2

