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

歡迎訪問 生活随笔!

生活随笔

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

python

python nose测试框架全面介绍十---用例的跳过

發布時間:2024/4/17 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python nose测试框架全面介绍十---用例的跳过 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? 又來寫nose了,這次主要介紹nose中的用例跳過應用,之前也有介紹,見python nose測試框架全面介紹四,但介紹的不詳細。下面詳細解析下

nose自帶的SkipTest

? ?先看看nose自帶的SkipTest典型應用

? ?應用一:

‘'' @auth:hu ’'' from nose.plugins.skip import SkipTest @attr(mode=1) def test_learn_1():raise SkipTest

但這種SkipTest在實際的日志中沒有顯示Skip關鍵字

應用二:

如果想要在執行用例前判斷相關字雄姿英發再進行用例跳過,如下

'''@author: huzq ''' import nose import nose.plugins.multiprocess from testtools import TestCase from nose import SkipTest from nose.plugins.skip import Skip import unittestclass TestClass():def setUp(self):print "MyTestClass setup"if "xxx" in "qqqq":raise SkipTest("adfdfd")def Testfunc1(self):print "this is Testfunc01"

每個用例前都會進行判斷,并進行跳過操作

應用三:

可用覺得寫在代碼中太麻煩,SkipTest也可以當裝飾器來進行,如下

''' @author: huzq ''' import nose import nose.plugins.multiprocess from testtools import TestCase from nose import SkipTest from nose.plugins.skip import Skip import unittestclass TestClass():@classmethoddef setUpClass(self):print "xxxxxx"def setUp(self):print "MyTestClass setup"def tearDown(self):print "MyTestClass teardown"@SkipTestdef Testfunc1(self):print "this is Testfunc01"

要注意的時,如果用裝飾器形式,SkipTest后不能接具體原因,如果要接具體原因,只能用unittest的方法寫,如下

@unittest.skip("I don't want to run this case.")

?

SkipTest可放在SetUpclass、SetUp、Test中

?

?

使用unittest的skip


什么都是沒有完美的,如果想用裝飾器來進行用例判斷并跳過,nose自帶的skiptest沒法完成。好在unittest有更好的解決方案。

就直接貼官網的例子吧,nose也支持?

class MyTestCase(unittest.TestCase):@unittest.skip("demonstrating skipping")def test_nothing(self):self.fail("shouldn't happen")@unittest.skipIf(mylib.__version__ < (1, 3),"not supported in this library version")def test_format(self):# Tests that work for only a certain version of the library.pass@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")def test_windows_support(self):# windows specific testing codepass

?

轉載于:https://www.cnblogs.com/landhu/p/9200969.html

總結

以上是生活随笔為你收集整理的python nose测试框架全面介绍十---用例的跳过的全部內容,希望文章能夠幫你解決所遇到的問題。

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