Python unittest - assertNotAlmostEqual() function Last Updated : 29 Aug, 2020 Comments Improve Suggest changes Like Article Like Report assertNotAlmostEqual() in Python is a unittest library function that is used in unit testing to check whether two given values are not approximately. This function will take five parameters as input and return a boolean value depending upon the assert condition. This function check that first and second are not approximately equal by computing the difference, rounding to the given number of decimal places (default 7), and comparing to zero. If delta is supplied instead of places then the difference between first and second must be less or equal to delta. Syntax: assertNotAlmostEqual(first, second, places=7, message=None, delta=None) Parameters: assertNotAlmostEqual() accept three parameters which are listed below with explanation: first: first input value (integer)second: second input value (integer)places: decimal places for approximationmessage: a string sentence as a message which got displayed when the test case got failed.delta: delta value for approximation Listed below are two different examples illustrating the positive and negative test case for given assert function: Example : Python3 # test suite import unittest class TestStringMethods(unittest.TestCase): # negative test function to test if values are almost not-equal with place def test_negativeWithPlaces(self): first = 4.4555 second = 4.4566 decimalPlace = 2 # error message in case if test case got failed message = "first and second are almost equal." # assert function() to check if values are almost not-equal self.assertNotAlmostEqual(first, second, decimalPlace, message) # positive test function to test if values are almost not-equal with place def test_positiveWithPlaces(self): first = 4.4555 second = 4.4566 decimalPlace = 3 # error message in case if test case got failed message = "first and second are almost equal." # assert function() to check if values are almost not-equal self.assertNotAlmostEqual(first, second, decimalPlace, message) # negative test function to test if values are almost not-equal with delta def test_negativeWithDelta(self): first = 4.4555 second = 4.4566 delta = 0.002 # error message in case if test case got failed message = "first and second are almost equal." # assert function() to check if values are almost equal self.assertNotAlmostEqual(first, second, None, message, delta) # positive test function to test if values are almost not-equal with delta def test_positiveWithDelta(self): first = 4.4555 second = 4.4566 delta = 0.0001 # error message in case if test case got failed message = "first and second are almost equal." # assert function() to check if values are almost not-equal self.assertNotAlmostEqual(first, second, None, message, delta) if __name__ == '__main__': unittest.main() Output: FF.. ====================================================================== FAIL: test_negativeWithDelta (__main__.TestStringMethods) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/ebb259873a4edc722a83da1a694e0ce1.py", line 34, in test_negativeWithDelta self.assertNotAlmostEqual(first, second, None, message, delta) AssertionError: 4.4555 == 4.4566 within 0.002 delta : first and second are almost equal. ====================================================================== FAIL: test_negativeWithPlaces (__main__.TestStringMethods) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/ebb259873a4edc722a83da1a694e0ce1.py", line 14, in test_negativeWithPlaces self.assertNotAlmostEqual(first, second, decimalPlace, message) AssertionError: 4.4555 == 4.4566 within 2 places : first and second are almost equal. ---------------------------------------------------------------------- Ran 4 tests in 0.001s FAILED (failures=2) Reference: https://docs.python.org/3/library/unittest.html Comment More infoAdvertise with us Next Article Python unittest - assertAlmostEqual() function S Shivam.Pradhan Follow Improve Article Tags : Python Python unittest-library Python Testing Practice Tags : python Similar Reads Python Unittest Tutorial | Unit Testing in Python using unittest Framework Unit Testing is the first level of software testing where the smallest testable parts of software are tested. This is used to validate that each software unit performs as designed. The unittest test framework is Python xUnit style framework. In this article, we will learn about unittest framework wi 7 min read Python Unittest Comparison AssertionsPython - assertLess() function in unittestassertLess() in Python is an unittest library function that is used in unit testing to check whether the first given value is less than the second value or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. This function check that 2 min read Python - assertGreater() function in unittestassertGreater() in Python is an unittest library function that is used in unit testing to check whether the first given value is greater than the second value or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. This function check 2 min read Python - assertGreaterEqual() function in unittestassertGreaterEqual() in Python is an unittest library function that is used in unit testing to check whether the first given value is greater than or equal to the second value or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. Th 2 min read Python - assertLessEqual() function in unittestassertLessEqual() in Python is an unittest library function that is used in unit testing to check whether the first given value is less than or equal to the second value or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. This fun 2 min read Python Unittest Approximate Value AssertionsPython unittest - assertNotAlmostEqual() functionassertNotAlmostEqual() in Python is a unittest library function that is used in unit testing to check whether two given values are not approximately. This function will take five parameters as input and return a boolean value depending upon the assert condition. This function check that first and se 3 min read Python unittest - assertAlmostEqual() functionassertAlmostEqual() in Python is a unittest library function that is used in unit testing to check whether two given values are almost equal or not. This function will take five parameters as input and return a boolean value depending upon the assert condition. This function check that first and sec 3 min read Python Unittest Type AssertionsPython unittest - assertIsInstance() functionassertIsInstance() in Python is a unittest library function that is used in unit testing to check whether an object is an instance of a given class or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. If the object is an instance o 2 min read Python unittest - assertNotIsInstance() functionassertNotIsInstance() in Python is a unittest library function that is used in unit testing to check whether an object is not an instance of a given class or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. If the object is not an 2 min read Python Unittest Membership AssertionsPython unittest - assertIn() functionassertIn() in Python is a unittest library function that is used in unit testing to check whether a string is contained in other or not. This function will take three string parameters as input and return a boolean value depending upon the assert condition. If the key is contained in container strin 2 min read Python unittest - assertNotIn() functionassertNotIn() in Python is a unittest library function that is used in unit testing to check whether a string is not contained in other. This function will take three string parameters as input and return a boolean value depending upon the assert condition. If the key is not contained in container s 2 min read Python Unittest Equality AssertionsPython unittest - assertEqual() functionassertEqual() is a function from Python's unittest library used for unit testing. It checks whether two values are equal and returns a boolean result based on the condition. If both values are equal, the test passes otherwise it fails and raises an AssertionError with an optional error message. For 3 min read Python unittest - assertNotEqual() functionassertNotEqual() in Python is a unittest library function that is used in unit testing to check the inequality of two values. This function will take three parameters as input and return a boolean value depending upon the assert condition. If both input values are unequal assertNotEqual() will retur 2 min read Python Unittest None AssertionsPython unittest - assertIsNotNone() functionassertIsNotNone() in Python is a unittest library function that is used in unit testing to check that input value is not None. This function will take two parameters as input and return a boolean value depending upon assert condition. If input value is not equal to None assertIsNotNone() will return 2 min read Python unittest - assertIsNone() functionassertIsNone() in Python is a unittest library function that is used in unit testing to check that input value is None or not. This function will take two parameters as input and return a boolean value depending upon assert condition. If input value is equal to None assertIsNone() will return true e 2 min read Python Unittest Identity AssertionsPython unittest - assertIn() functionassertIn() in Python is a unittest library function that is used in unit testing to check whether a string is contained in other or not. This function will take three string parameters as input and return a boolean value depending upon the assert condition. If the key is contained in container strin 2 min read Python unittest - assertIsNot() functionassertIsNot() in Python is a unittest library function that is used in unit testing to test whether first and second input value don't evaluate to the same object or not. This function will take three parameters as input and return a boolean value depending upon the assert condition. If both inputs 2 min read Python Unittest Boolean AssertionsPython unittest - assertFalse() functionassertFalse() in Python is a unittest library function that is used in unit testing to compare test value with false. This function will take two parameters as input and return a boolean value depending upon the assert condition. If test value is false then assertFalse() will return true else return 2 min read Python unittest - assertTrue() functionassertTrue() in Python is a unittest library function that is used in unit testing to compare test value with true. This function will take two parameters as input and return a boolean value depending upon the assert condition. If test value is true then assertTrue() will return true else return fal 2 min read Like