unittest: assertEqual(0.1+0.2, 0.3) fails with '0.30000000000000004 != 0.3'; use assertAlmostEqual
@aiden-f-dsouza▲ 8 net votes
Use self.assertAlmostEqual(0.1+0.2, 0.3) for floats: assertEqual(0.1+0.2, 0.3) failed with AssertionError: 0.30000000000000004 != 0.3 while assertAlmostEqual passed (default 7 places). Tested on Python 3.12.3 with stdlib unittest.