国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

詳解Python nose單元測試框架的安裝與使用

2020-02-16 11:11:47
字體:
來源:轉載
供稿:網友

本文介紹了Python nose單元測試框架的安裝與使用 ,分享給大家,具體如下:

安裝(Python2下安裝)

pip install nose

原理與命名規則

Nose會自動查找源文件、目錄或者包中的測試用例,符合正則表達式(?:^|[/b_/.%s-])[Tt]est,以及TestCase的子類都會被識別并執行。

例如:我們可以將python腳本文件名以“_test”結尾或包含“_test_”,方法名以“_test”結尾。

使用方法

查看所有nose相關命令:

nosetests -h

執行并捕獲輸出:

nosetests -s

查看nose的運行信息和調試信息:

nosetests -v9

輸出xml結果報告:

nosetests --with-xunit

支持測試方法傳參:

1)安裝:需要下載插件“nose_ittr”:

pip install nose_ittr

2)腳本中使用示例:

# -*- coding: utf-8 -*-import osfrom nose.tools import nottest,istestfrom nose_ittr import IttrMultiplier, ittrcurr_dir = os.path.dirname(os.path.abspath(__file__))class TestCheckChannels(object):  __metaclass__ = IttrMultiplier  '''    測試方法傳入兩個參數    參數一:channels_txt_name    參數二:check_list_txt_name    使用方法:通過“self.參數名”進行調用  '''  @istest  @ittr(channels_txt_name=["channels.txt"],check_list_txt_name=["check_list.txt"])   def test_check_channels(self):    channels_txt_path = os.path.join(curr_dir,self.channels_txt_name)    check_list_txt_path = os.path.join(curr_dir,self.check_list_txt_name)    the_channels = []    with open(channels_txt_path) as channels:      for line in channels.readlines():        line = line.strip()        if line != '':          the_channels.append(line)    with open(check_list_txt_path) as check_list:      check_items = check_list.readlines()      for check_item in check_items:        if check_item.strip() in the_channels:          pass        elif check_item=='/n':          pass        else:          print check_item

3)執行示例:

nosetests --with-html-output --html-out-file=result1.html -v --with-setup-ittr

以上執行將輸出html結果報告,但是需要先安裝插件:

1)安裝:

需要下載插件,在解壓縮后在命令行中cd到該目錄下:

python setup.py install

通過命令行安裝:

pip install nosehtmloutput-2pip install nose-html-reporting

2)在待測路徑打開cmd使用命令如下,就可以執行測試并生成測試結果html文件了:

nosetests --with-html-output --html-out-file=result1.html

工具nose.tools的使用:

1)測試腳本中引入:from nose.tools import nottest,istest;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邮箱| 三河市| 烟台市| 北碚区| 子洲县| 珠海市| 比如县| 滁州市| 保德县| 日喀则市| 南川市| 文成县| 宁海县| 筠连县| 金坛市| 湘乡市| 日土县| 苍溪县| 大理市| 贺州市| 绥德县| 武夷山市| 德州市| 宜君县| 元氏县| 邮箱| 延川县| 朝阳区| 犍为县| 宜良县| 茌平县| 瓮安县| 长宁区| 嘉禾县| 宣化县| 三原县| 茂名市| 太仓市| 延安市| 武夷山市| 三河市|