Python unittest - assertIsNot() function Last Updated : 29 Aug, 2020 Comments Improve Suggest changes Like Article Like Report assertIsNot() 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 don't evaluate to the same object then assertIsNot() will return true else return false. Syntax: assertIsNot(firstValue, secondValue, message) Parameters: assertIsNot() accept three parameters which are listed below with explanation: firstValue variable of any type which is used in the comparison by functionsecondValue: variable of any type which is used in the comparison by functionmessage: a string sentence as a message which got displayed when the test case got failed. Listed below are two different examples illustrating the positive and negative test case for given assert function: Example 1: Negative Test case Python3 # unit test case import unittest class DummyClass: x = 5 class TestMethods(unittest.TestCase): # test function def test_negative(self): firstValue = DummyClass() secondValue = firstValue # error message in case if test case got failed message = "First value & second value evaluates to same object !" # assertIs() to check that if first & second don't evaluated to same object self.assertIsNot(firstValue, secondValue, message) if __name__ == '__main__': unittest.main() Output: F ====================================================================== FAIL: test_negative (__main__.TestMethods) ---------------------------------------------------------------------- Traceback (most recent call last): File "p1.py", line 15, in test_negative self.assertIsNot(firstValue, secondValue, message) AssertionError: unexpectedly identical: <__main__.DummyClass object at 0x7f75c2e33b70> : First value & second value evaluates to same object! ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) Example 2: Positive Test case Python3 # unit test case import unittest class DummyClass: x = 5 class TestMethods(unittest.TestCase): # test function to test object equality of two value def test_positive(self): firstValue = DummyClass() secondValue = DummyClass() # error message in case if test case got failed message = "First value and second value evaluated to same object !" # assertIs() to check that if first & second don't evaluates to same object self.assertIsNot(firstValue, secondValue, message) if __name__ == '__main__': unittest.main() Output: . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK Reference: https://docs.python.org/3/library/unittest.html Comment More infoAdvertise with us Next Article Python unittest - assertFalse() 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