Python - assertLess() function in unittest Last Updated : 01 Nov, 2020 Comments Improve Suggest changes Like Article Like Report assertLess() 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 if the first given value is less than the second value and returns true if it is so, else returns false if the first value is not less than the second value. Syntax: assertLess(first, second, message=None) Parameters: assertLess() accept three parameters which are listed below with explanation: first: first input value (integer)second: second input value (integer)message: a string sentence as a message which got displayed when the test case got failed. Listed below is an example illustrating the positive and negative test case for given assert function: Example 1: If the first value is not less that second value. Python3 # test suite import unittest class TestStringMethods(unittest.TestCase): # negative test function to test if # values1 is less than value2 def test_negativeForLess(self): first = 6 second = 5 # error message in case if test case got failed message = "first value is not less that second value." # assert function() to check if values1 is # less than value2 self.assertLess(first, second, message) # main for function call if __name__ == '__main__': unittest.main() Output: F ====================================================================== FAIL: test_negativeForLess (__main__.TestStringMethods) ---------------------------------------------------------------------- Traceback (most recent call last): File "p1.py", line 13, in test_negativeForLess self.assertLess(first, second, message) AssertionError: 5 not less than 5 : first value is not less that second value. ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) Example 2: If the first given value is less than the second value Python # test suite import unittest class TestStringMethods(unittest.TestCase): # positive test function to test if # values are almost equal with place def test_positiveForLess(self): first = 2 second = 3 # error message in case if test case got failed message = "first value is not less that second value." # assert function() to check if values1 is # less than value2 self.assertLess(first, second, message) # main for function call if __name__ == '__main__': unittest.main() Output: . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK Comment More infoAdvertise with us Next Article Python - assertGreater() function in unittest 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