Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python unittest - assertTrue() function
Next article icon

Python unittest – assertFalse() function

Last Updated : 29 Aug, 2020
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
Python unittest - assertTrue() function

S

Shivam.Pradhan
Improve
Article Tags :
  • Python
  • Python Testing
  • Python unittest-library
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 Assertions

    • Python - assertLess() function in unittest
      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
      2 min read

    • Python - assertGreater() function in unittest
      assertGreater() 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 unittest
      assertGreaterEqual() 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 unittest
      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 fun
      2 min read

    Python Unittest Approximate Value Assertions

    • Python unittest - assertNotAlmostEqual() function
      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 se
      3 min read

    • Python unittest - assertAlmostEqual() function
      assertAlmostEqual() 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 Assertions

    • Python unittest - assertIsInstance() function
      assertIsInstance() 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() function
      assertNotIsInstance() 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 Assertions

    • Python unittest - assertIn() function
      assertIn() 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() function
      assertNotIn() 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 Assertions

    • Python unittest - assertEqual() function
      assertEqual() 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() function
      assertNotEqual() 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 Assertions

    • Python unittest - assertIsNotNone() function
      assertIsNotNone() 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() function
      assertIsNone() 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 Assertions

    • Python unittest - assertIn() function
      assertIn() 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() function
      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
      2 min read

    Python Unittest Boolean Assertions

    • Python unittest - assertFalse() function
      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
      2 min read

    • Python unittest - assertTrue() function
      assertTrue() 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

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences