Summary of assertions for Python's unittest framework

Source: Internet
Author: User

The common assertion methods are as follows:

Assertfalse: Returns True;self.assertfalse when false (expression, "message printed when expression is true")

Asserttrue: Returns True;self.asserttrue when True (expression, "message printed when expression is false")

Asserequal: Equality returns true;self.assertequal (expression 1, expression 2, "expression 1 is not equal to expression 2 o'clock printed message")

Assertnotequal: Unequal returns true;self.assertnotequal (expression 1, expression 2, "expression 1 equals expression 2 o'clock printed message")

Assertisnone: Does not exist, then pass;self.assertisnone (expression, "If expression exists for printed message")

Assertisnotnone: exists, then pass;self.assertisnotnone (expression, "if the expression does not exist with printed message")

In the official documents to see the tidying up, some too late translation.

Assertalmostequal (first, second[, places, ...])

For decimals, place is supposed to be at least a few equal Boolean values of 1 (the default is 7), and the assertion fails if it differs within the place bit.

Assertdictcontainssubset (expected, actual[, MSG])

Check if the actual is over-expected

Assertdictequal (d1, d2[, MSG])

Whether the dictionary is the same

Assertequal (First, second[, MSG])

Two numbers before and after the failure

Assertfalse (expr[, MSG])

Checks whether an expression is false

Assertgreater (A, b[, MSG])

Same as Self.asserttrue (a > B), but with more set conditions.

Assertgreaterequal (A, b[, MSG])

Same as Self.asserttrue (a > =b) usage, but with more set conditions.

Assertin (Member, container[, MSG])

Self.asserttrue (A in B)

Assertis (Expr1, expr2[, MSG])

Asserttrue (A is B)

Assertisinstance (obj, cls[, MSG])

Isinstance (A, B)

Assertisnone (obj[, MSG])

OBJ is none.

Assertisnot (Expr1, expr2[, MSG])

A is not B.

Assertisnotnone (obj[, MSG])

OBJ is not none.

Assertitemsequal (Expected_seq, actual_seq[, MSG])

An unordered sequence-specific comparison.

Assertless (A, b[, MSG])

Just like Self.asserttrue (a < b), but with a nicer default message.

Assertlessequal (A, b[, MSG])

Just like Self.asserttrue (a <= b), but with a nicer default message.

Assertlistequal (List1, list2[, MSG])

List1 and List2 are equal.

Assertmultilineequal (First, second[, MSG])

Asserts that 2 multi-line strings are equal

Assertnotalmostequal (First, second[, ...])

Fail if the objects is equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing, the between the and the objects are less than the given delta.

Assertnotalmostequals (First, second[, ...])

Fail if the objects is equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing, the between the and the objects are less than the given delta.

Assertnotequal (First, second[, MSG])

Fail if the objects is equal as determined by the ' = = '

Assertnotequals (First, second[, MSG])

Fail if the objects is equal as determined by the ' = = '

Assertnotin (Member, container[, MSG])

Just like Self.asserttrue (a No in B), but with a nicer default message.

Assertnotisinstance (obj, cls[, MSG])

Included for symmetry with Assertisinstance.

Assertnotregexpmatches (text, unexpected_regexp)

If the text matches the regular expression, it will fail.

Assertraises (excclass[, Callableobj])

Unless the Excclass class throws an exception failure

Assertraisesregexp (expected_exception, ...)

The message is considered to match a regular expression in the case of an exception being thrown.

Assertregexpmatches (text, expected_regexp[, MSG])

The test fails unless the text matches the regular expression.

Assertsequenceequal (seq1, seq2[, MSG, Seq_type])

An equality assertion for ordered sequences (like lists and tuples).

Assertsetequal (Set1, set2[, MSG])

A set-specific Equality assertion.

Asserttrue (expr[, MSG])

Check the expression is true.

Asserttupleequal (Tuple1, tuple2[, MSG])

A tuple-specific Equality assertion.

Assert_ (expr[, MSG])

Check the expression is true.

Summary of assertions for Python's unittest framework

Related Article

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.