Open In App

Python unittest - assertFalse() function

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

assertFalse() 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 false.

Syntax: assertFalse(testValue, message)

Parameters: assertFalse() accepts two parameters which are listed below with explanation:

  • testValue:  variable of a boolean type which is used in the comparison by function
  • message: 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 TestStringMethods(unittest.TestCase):
    # test function 
    def test_negative(self):
        testValue = True
        # error message in case if test case got failed
        message = "Test value is not false."
        # assetFalse() to check test value as false
        self.assertFalse( testValue, message)

if __name__ == '__main__':
    unittest.main()

Output:

F
======================================================================
FAIL: test_negative (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "p1.py", line 11, in test_negative
    self.assertFalse( testValue, message)
AssertionError: True is not false : Test value is not false.

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)


Example 2: Positive Test case

Python3
# unit test case
import unittest

class TestStringMethods(unittest.TestCase):
    # test function 
    def test_positive(self):
        testValue = False
        # error message in case if test case got failed
        message = "Test value is not false."
        # assertFalse() to check test value as false
        self.assertFalse( testValue, message)

if __name__ == '__main__':
    unittest.main()

Output:

.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK



Reference: https://docs.python.org/3/library/unittest.html


Next Article
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy