- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are assertions in Python and how are they carried out?
An assertion is a sanity-test when you are done with your testing of a program.
An assertion is similar to a raise-if statement (or to be more precise, a raise-if-not statement). An expression is tested, and if the result turns out to be false, an exception is raised. Assertions are carried out by using the assert statement.
Programmers often put assertions at the start of a function to check for valid input, and after a function call to check for valid output. Using assert statement below
x,y = 8,8 assert x<y, 'x and y are equal'
Traceback (most recent call last): File "C:/Users/TutorialsPoint1/PycharmProjects/TProg/Exception handling/assertionerror1.py", line 9, in <module> assert x<y, 'x and y are equal' AssertionError: x and y are equal
Equivalent code without assert statement producing same output is as follows
x,y =8,8 if not x<y : raise AssertionError('x and y are equal')
Traceback (most recent call last): File "C:/Users/TutorialsPoint1/PycharmProjects/TProg/Exception handling/assertionerror1.py", line 7, in <module> raise AssertionError('x and y are equal') AssertionError: x and y are equal
- What are assertions in Selenium with python?
- What are contra entries and how are they recorded?
- What are A-shares and how are they traded?
- What are FIRST and FOLLOW and how they are computed?
- What are Microwaves? What are they used for?
- What Are Krugerrands and What Do They Mean?
- What are Digital Signatures and how do they work?
- What are native methods in Java and where are they used?
- How are iOS and Android similar? How are they different?
- What are Protein mats? How are they helpful to the environment?
- What is a plateau? How are they formed?
- What are assertions available to test relational comparisons in Selenium with python?
- Why are there two Irelands? What are they called independently?
- How many types of Result Sets are there in JDBC What are they?
- What are Pagoda’s and why they were built?