Selenium2+python自动化70-unittest之跳过用例(skip)
前言
當(dāng)測(cè)試用例寫(xiě)完后,有些模塊有改動(dòng)時(shí)候,會(huì)影響到部分用例的執(zhí)行,這個(gè)時(shí)候我們希望暫時(shí)跳過(guò)這些用例。
或者前面某個(gè)功能運(yùn)行失敗了,后面的幾個(gè)用例是依賴(lài)于這個(gè)功能的用例,如果第一步就失敗了,后面的用例也就沒(méi)必要去執(zhí)行了,直接跳過(guò)就行,節(jié)省用例執(zhí)行時(shí)間。
?
一、skip裝飾器
skip裝飾器一共有四個(gè)
@unittest.skip(reason)
Unconditionally skip the decorated test. reason should describe why the test is being skipped.
翻譯:無(wú)條件跳過(guò)用例,reason是說(shuō)明原因
Skip the decorated test if condition is true.
翻譯:condition為true的時(shí)候跳過(guò)
Skip the decorated test unless condition is true.
翻譯:condition為False的時(shí)候跳過(guò)
Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure.
翻譯:斷言的時(shí)候跳過(guò)()
?
二、skip案例
運(yùn)行結(jié)果:
測(cè)試1
測(cè)試4
.ssx
----------------------------------------------------------------------
Ran 4 tests in 0.003s
OK (skipped=2, expected failures=1)
?
三、跳過(guò)整個(gè)測(cè)試類(lèi)
?
四、參考代碼:
# coding:utf-8
import unittest
class Test(unittest.TestCase):
??? @unittest.skip(u"無(wú)條件跳過(guò)此用例")
??? def test_1(self):
??????? print "測(cè)試1"
??? @unittest.skipIf(True, u"為T(mén)rue的時(shí)候跳過(guò)")
??? def test_2(self):
??????? print "測(cè)試2"
??? @unittest.skipUnless(False, u"為False的時(shí)候跳過(guò)")
??? def test_3(self):
??????? print "測(cè)試3"
??? @unittest.expectedFailure
??? def test_4(self):
??????? print "測(cè)試4"
??????? self.assertEqual(2, 4, msg=u"判斷相等")
if __name__ == "__main__":
??? unittest.main()
?
** 作者:上海-悠悠 QQ交流群:588402570**轉(zhuǎn)載于:https://www.cnblogs.com/yoyoketang/p/7056905.html
總結(jié)
以上是生活随笔為你收集整理的Selenium2+python自动化70-unittest之跳过用例(skip)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 我的wmware
- 下一篇: Python: ImportReques