Python3 UnitTest Assertion

Source: Internet
Author: User

  There are three main types of assertions in UnitTest :
1. Basic Boolean assertion: either correct or false validation
2. Compare assertions, such as comparing the values of two variables (not very different from the Boolean assertion above, mainly by comparing the value of the two variables worth the Boolean)
3. Complex assertions (less commonly used, like asserting two lists, tuples, etc.)

  1. Basic Boolean assertions

This is the assertion parameter of the right and wrong, of course, there are some more assertions. There is one thing in common: there is a msg parameter, and if you specify the value of the MSG parameter, the information is returned as a failed error message. There are mainly the following:


  2. Compare assertions

Assertalmostequal (first, second, places = 7, msg = none, Delta = none)
Verify that first is approximately equal to second. Palces: Specifies the number of digits after the decimal point, which defaults to 7

Assertnotalmostequal (first, second, places, MSG, Delta)
Verify that first is not approximately equal to second. Palces: Specifies the number of digits after the decimal point, which defaults to 7

Note: In the above two functions, if the delta specifies a value, the difference between first and second must be ≤delta

Assertgreater (first, second, msg = None)
Verify First > second, otherwise fail

Assertgreaterequal (first, second, msg = None)
Verify First≥second, otherwise fail

Assertless (first, second, msg = None)
Verify first < second, otherwise fail

Assertlessequal (first, second, msg = None)
Verify First≤second, otherwise fail

Assertregexpmatches (text, regexp, msg = None)
Verify that the regular expression regexp searches for the text that matches. RegExp: usually use Re.search ()

Assertnotregexpmatches (text, regexp, msg = None)
Verifies that the regular expression regexp searches for text that does not match. RegExp: usually use Re.search ()

  3. Complex assertions

  

Python3 UnitTest Assertion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.