- Reprinted feeling too lazy to write their own people to write it enough, reproduced easily query their own use
-
unittest asserts there are three main types:
-
- The basic Boolean assertion that: either right or wrong verification
- Compare assertion, such as the value comparing two variables (Boolean with the above assertion is not very different, mainly worth a Boolean value by comparing two variables)
-
Complex asserted (generally relatively small, as asserted two lists, tuples etc.)
- The basic assertion Boolean
- This parameter is the assertion of right and wrong, of course, there are some relatively assertion. We have one thing in common: there is a msg parameter, if the value of the msg parameter is specified, then the information is returned as an error message failed. Mainly in the following:
-
Compare assertion
assertAlmostEqual (first, second, places = 7, msg = None, delta = None)
Approximately equal to first verify second. palces: Specifies the number of decimal places, the default is 7
assertNotAlmostEqual (first, second, places, msg, delta)
First verification is not approximately equal to second. palces: Specifies the number of decimal places, the default is 7
NOTE: In the above-described two functions, if the delta value is specified, then the difference between the first and the second must ≤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 regular expression regexp search for matching text text. regexp: usually re.search ()
assertNotRegexpMatches (text, regexp, msg = None)
Verify regular expression regexp does not match the search text text. regexp: usually re.search ()
-
Complex assertions
----------------
Disclaimer: This article is CSDN blogger "struggling white 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https://blog.csdn.net/qq_29699799/article/details/79947882