assertNotAlmostEqual
assertNotAlmostEqual is a test assertion method provided by the Python unittest framework that verifies two numeric values are not close to each other within a specified tolerance. It is used to assert that the difference between two numbers exceeds a threshold, rather than being within an acceptable range. The method is defined in the TestCase class:
def assertNotAlmostEqual(self, first, second, places=7, msg=None, delta=None)
```
The first two positional arguments are the values to compare. The optional `places` argument specifies the number
When the absolute difference between `first` and `second` is less than or equal to the calculated tolerance,
self.assertNotAlmostEqual(0.123456, 0.123457, places=5) # passes, diff is 0.000001 > 10⁻⁵
self.assertNotAlmostEqual(1.0, 1.0 + 1e-8, delta=1e-7) # fails
```
This assertion is useful when verifying that two results are significantly distinct, such as testing that