unittest框架-skip跳過測試和預期失敗
阿新 • • 發佈:2019-02-18
概要
當測試用例寫完後,有些模組有改動時候,會影響到部分用例的執行,這個時候我們希望暫時跳過這些用例。
或者前面某個功能執行失敗了,後面的幾個用例是依賴於這個功能的用例,如果第一步就失敗了,後面的用例也就沒必要去執行了,直接跳過就行,節省用例執行時間。
skip裝飾器一共有四個
@
unittest.
skip
(reason)
Unconditionally skip the decorated test. reason should describe why the test is being skipped.
翻譯:無條件跳過用例,reason是說明原因
@
unittest.
skipIf
(conditionSkip the decorated test if condition is true.
翻譯:condition為true的時候跳過
@
unittest.
skipUnless
(condition, reason)Skip the decorated test unless condition is true.
翻譯:condition為False的時候跳過
@
unittest.
expectedFailure
Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure.
翻譯:預期設定失敗,跳過測試