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