Python - assertLessEqual() function in unittest Last Updated : 24 Oct, 2020 Comments Improve Suggest changes Like Article Like Report assertLessEqual() 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 function checks that if the first given value is less than or equal to the second value and returns true if it is so, else return false if the first value is not less than or equal to the second value. Syntax: assertLessEqual(first, second, message=None) Parameters: assertLessEqual() 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: Python3 # test suite import unittest class TestStringMethods(unittest.TestCase): # negative test function to test if values1 is less or equal than value2 def test_negativeForLessEqual(self): first = 6 second = 5 # error message in case if test case got failed message = "first value is not less than or equal to second value." # assert function() to check if values1 is less or equal than value2 self.assertLessEqual(first, second, message) if __name__ == '__main__': unittest.main() Output: F ====================================================================== FAIL: test_negativeForLessEqual (__main__.TestStringMethods) ---------------------------------------------------------------------- Traceback (most recent call last): File "p1.py", line 13, in test_negativeForLessEqual self.assertLessEqual(first, second, message) AssertionError: 6 not less than or equal to 5 : first value is not less than or equal to second value. ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) Example 2: Python # test suite import unittest class TestStringMethods(unittest.TestCase): # positive test function to test if value1 is less or equal than value2 def test_positiveForLessEqual(self): first = 4 second = 4 # error message in case if test case got failed message = "first value is not less than or equal to second value." # assert function() to check if values1 is less or equal than value2 self.assertLessEqual(first, second, message) if __name__ == '__main__': unittest.main() Output: . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK Comment More infoAdvertise with us S Shivam.Pradhan Follow Improve Article Tags : Python Python unittest-library Python Testing Practice Tags : python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 5 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like