更新时间:2022-01-20 13:46:45
[本文出自天外归云的博客园]
pip install nose
nosetests -h
nosetests -s
nosetests -v9
nosetests --with-xunit
pip install nose_ittr
2)脚本中使用示例:
# -*- coding: utf-8 -*- import os from nose.tools import nottest,istest from nose_ittr import IttrMultiplier, ittr curr_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结果报告,但是需要先安装插件:
python setup.py install
pip install nosehtmloutput-2
pip install nose-html-reporting
2)在待测路径打开cmd使用命令如下,就可以执行测试并生成测试结果html文件了:
nosetests --with-html-output --html-out-file=result1.html
from nose.tools import nottest,istest from nose.tools import assert_equal class TestClass: def test_one(self): x = "this" assert 'h' in x def test_two(self): x = "hello" assert hasattr(x, 'check') @nottest def test_three(self): assert True @istest def xxxxx(self): assert True class test_haha(): def setUp(self): print("============test class setup==============") def teardown(self): print("============test class teardown==============") def test_xxx(self): print "test_xxx" assert_equal(9, 9) def test_kkk(self): print "test_kkk" assert_equal(1, 1)