Learning unittest 2: skip use cases

Skip unittest test case execution

@ unittest. skip ( Reason skip this decorated decoration test. reason is the reason the test was skipped.
@ unittest. skipIf ( Condition , reason when the condition when true, skipping the test to be decorated.
@ unittest. skipUnless ( Condition , reason to skip the decorated test, unless the condition is true.
@ unittest. expectedFailure  The test is expected to mark a failure. If the test is not passed, it would be considered a successful test; If the test passes, the test is considered a failure.
Example:
Import the unittest 


class Test_Study2 (of unittest.TestCase): 

    DEF the setUp (Self):
         Print ( ' Start ====== ' ) 

    DEF the tearDown (Self):
         Print ( ' End ====== ' ) 

    # forced to skip skip this embodiment with 
    @ unittest.skip ( ' skip this use case ' )
     DEF test_case1 (Self):
         Print ( " RUN Test Case 1111 " ) 

    DEF test_case2, (Self):
         Print ( " RUN Test Case 2222 ") 

    @ Unittest.skipIf ( . 3> 2, " if the condition is true, skip this use case " )
     DEF test_case3 (Self):
         Print ( " RUN Test Case 3333 " ) 

    @ unittest.skipUnless ( . 3 <2, " unless the conditions true, otherwise skip use case " )
     DEF test_case4 (Self):
         Print ( " RUN Test Case 4444 " ) 

    DEF test_case5 (Self):
         Print ( " RUN Test Case 5555 " ) 


IF  the __name__ == "__main__":
    unittest.main()

Results of the:

start======
run test case 2222
end======

start======
run test case 5555
end======
----------------------------------------------------------------------
Ran 5 tests in 0.001s
OK (skipped=3)
Process finished with exit code 0

 

For @unittest.expectedFailure individual instances:

   # Run through, marked as failed 
@ unittest.expectedFailure
     DEF test_case5 (Self): 
        self.assertEqual ( 1, 1 ) 

operating results 
FAILED (Unexpected SUCCESSES = 1 ) 

   # operation is not passed, marking the success 
@ unittest.expectedFailure
     DEF test_case5 (Self ): 
        self.assertEqual ( . 1 , 0) 

run results: 
the OK (failures The expected =. 1 )
        

 

Guess you like

Origin www.cnblogs.com/juankai/p/11579470.html