Selenium2+python Automated 70-unittest Skip use case (skip) "Reprint"

Source: Internet
Author: User

Objective

When the test case is finished, some of the modules are changed, which will affect the execution of some of the use cases, which we would like to temporarily skip.

Or the previous function failed to run, the following use cases are dependent on the use of this function, if the first step fails, the latter is not necessary to execute, directly skip the line, saving use case execution time.

One, skip decorator

Skip decorator a total of four

   @unittest.skip(reason)

    • Unconditionally skip the decorated test.  reason  should Describe why the test is being skipped.

      Translation: Skip the use case unconditionally, reason is the reason

    • @ unittest. skipIf ( condition ,   reason )

    • Skip the decorated test if  condition  is true.

      Translate: condition is true when skipping

    • @ unittest. skipunless ( condition ,   reason )

    • Skip the decorated test unless  condition  is true.

      Translate: condition to False when skipping

    • @ unittest. expectedfailure

    • Mark The test as an expected failure. If the test fails when run, the test was not counted as a failure.

      Translation: When the assertion is skipped (temporarily do not know what to use, did not understand, seemingly assertion failure, also become a use case pass.) )

Twoskip案例

Operation Result:

Test 1
Test 4
. SSX
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK (skipped=2, expected Failures=1)

Third, skip the entire test class

Iv. Reference Code:

# Coding:utf-8
Import UnitTest
Class Test (UnitTest. TestCase):

@unittest. Skip (U "Skip this use case unconditionally")
def test_1 (self):
print "Test 1"

@unittest. SkipIf (True, u "skips" when true)
def test_2 (self):
Print "Test 2"

@unittest. Skipunless (False, U "skips" when false)
def test_3 (self):
Print "Test 3"

@unittest. expectedfailure
def test_4 (self):
Print "Test 4"
Self.assertequal (2, 4, msg=u "equal judgment")

if __name__ = = "__main__":
Unittest.main ()

Selenium2+python Automated 70-unittest Skip use case (skip) "Reprint"

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.