日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Selenium2+python自动化70-unittest之跳过用例(skip)

發布時間:2024/4/15 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Selenium2+python自动化70-unittest之跳过用例(skip) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

當測試用例寫完后,有些模塊有改動時候,會影響到部分用例的執行,這個時候我們希望暫時跳過這些用例。

或者前面某個功能運行失敗了,后面的幾個用例是依賴于這個功能的用例,如果第一步就失敗了,后面的用例也就沒必要去執行了,直接跳過就行,節省用例執行時間。

?

一、skip裝飾器

skip裝飾器一共有四個

@unittest.skip(reason)

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

翻譯:無條件跳過用例,reason是說明原因

@unittest.skipIf(condition, reason)

Skip 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.

翻譯:斷言的時候跳過()

?

二、skip案例

運行結果:

測試1
測試4
.ssx
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK (skipped=2, expected failures=1)

?

三、跳過整個測試類

?

四、參考代碼:

# coding:utf-8
import unittest
class Test(unittest.TestCase):

??? @unittest.skip(u"無條件跳過此用例")
??? def test_1(self):
??????? print "測試1"

??? @unittest.skipIf(True, u"為True的時候跳過")
??? def test_2(self):
??????? print "測試2"

??? @unittest.skipUnless(False, u"為False的時候跳過")
??? def test_3(self):
??????? print "測試3"

??? @unittest.expectedFailure
??? def test_4(self):
??????? print "測試4"
??????? self.assertEqual(2, 4, msg=u"判斷相等")

if __name__ == "__main__":
??? unittest.main()

?

** 作者:上海-悠悠 QQ交流群:588402570**

轉載于:https://www.cnblogs.com/yoyoketang/p/7056905.html

總結

以上是生活随笔為你收集整理的Selenium2+python自动化70-unittest之跳过用例(skip)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。