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"