Python Assertion Encyclopedia

Source: Internet
Author: User

Reference Link: 51668672

1. Decimal bit blur equals

The most important thing about automation scripts is assertions, which can be set correctly to help us judge the results of test case execution.

With the help of a small colleague, a more detailed assertion method was compiled.

First, talk about the unittest commonly used assertions.

Commonly used in the following several, online a search a lot. Python version 2.7 or more can be called.

Assertion syntax Explain
Assertequal (A, B) Judging a==b
Assertnotequal (A, B) Judge A! =b
Asserttrue (x) BOOL (x) is True
Assertfalse (x) BOOL (x) is False
Assertis (A, B) A is B
Assertisnot (A, B) A is not B
Assertisnone (x) X is None
Assertisnotnone (x) X is not None
Assertin (A, B) A in B
Assertnotin (A, B) A not in B
Assertisinstance (A, B) Isinstance (A, B)
Assertnotisinstance (A, B) Not Isinstance (A, B)

second, some of the recently collated

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

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

Applies to decimals, Place is supposed to be at least several equal Boolean values to be 1(default is 7), if the Place The assertion fails if there are different bits within it.

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])

and the Self.asserttrue (a > B) Use the same , but more. Set Conditions  .

Assertgreaterequal (A, b[, MSG])

and the self.asserttrue (A > =b) Use the same , but more. Set Conditions  .

Assertin (Member, container[, MSG])

Self.asserttrue (A in B)

Assertis (Expr1, expr2[, MSG])

Asserttrue (A is B)

Assertisinstance (obj, cls[, MSG])

I Sinstance (A, b)

Assertisnone (obj[, MSG])

O BJ is None .

Assertisnot (Expr1, expr2[, MSG])

a is not B .

Assertisnotnone (obj[, MSG])

O BJ 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])

L ist1 and list2 are equal .

Assertmultilineequal (First, second[, MSG])

asserts that2 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])

equality assertions 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.


Third, in the UnitTest package to see the more complete assertion


Python Assertion Encyclopedia

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.