Python nose单元测试框架的安装与使用
[本文出自天外归云的博客园]
安装(Python2下安装)
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)
测试执行
测试结果
Python nose单元测试框架的安装与使用的更多相关文章
- Python nose单元测试框架结合requests库进行web接口测试
[本文出自天外归云的博客园] 之前写过一篇关于nose使用方法的博客.最近在做一元乐购产品的接口测试,结合着python的requests库可以很方便的进行web接口测试并生成测试结果.接口测试脚本示 ...
- Python 单元测试框架系列:聊聊 Python 的单元测试框架(一):unittest
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- python nose测试框架全面介绍七--日志相关
引: 之前使用nose框架时,一直使用--logging-config的log文件来生成日志,具体的log配置可见之前python nose测试框架全面介绍四. 但使用一段时间后,发出一个问题,生成的 ...
- python nose测试框架全面介绍十---用例的跳过
又来写nose了,这次主要介绍nose中的用例跳过应用,之前也有介绍,见python nose测试框架全面介绍四,但介绍的不详细.下面详细解析下 nose自带的SkipTest 先看看nose自带的S ...
- python nose测试框架全面介绍六--框架函数别名
之前python nose测试框架全面介绍二中介绍了nose框架的基本构成,但在实际应该中我们也会到setup_function等一系列的名字,查看管网后,我们罗列下nose框架中函数的别名 1.pa ...
- 聊聊 Python 的单元测试框架(二):nose 和它的继任者 nose2
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- Python Nose 自动化测试框架介绍
文章目录 1. unittest 简介 1.1 python 单元测试 1.2 unittest 测试框架 1.3 默认模式 1.4 手工模式 2. nose 扩展框架 2.1 `nose` 的安装和 ...
- Python自动单元测试框架
原文链接:http://www.ibm.com/developerworks/cn/linux/l-pyunit/ 软件的测试是一件非常乏味的事情,在测试别人编写的软件时尤其如此,程序员通常都只对编写 ...
- [转] Python自动单元测试框架
一.软件测试 大型软件系统的开发是一个很复杂的过程,其中因为人的因素而所产生的错误非常多,因此软件在开发过程必须要有相应的质量保证活动,而软件测试则是保证质量的关键措施.正像软件熵(software ...
随机推荐
- 转载:Kafka 之 中级 原作者:悟性
Kafka 之 中级 悟性 发表于 3年前 阅读 21353 摘要: Kafka配置介绍,原理介绍及生产者,消费者Java基本使用方法. 1. 配置 Ø Broker主要配置 参数 默认值 说 ...
- Apache Rewrite(大小写)
1.Rewrite规则简介: Rewirte 主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言.可基于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式.如果 ...
- Nginx防盗链的3种方法 文件防盗链 图片防盗链 视频防盗链 linux防盗链
Nginx 是一个很牛的高性能Web和反向代理服务器, 它具有有很多非常优越的特性: 在高连接并发的情况下,Nginx是Apache服务器不错的替代品,目前Web服务器调查显示Apache下降Ngni ...
- 【HTML】前端性能优化之CDN和WPO的比较
CDN通过将资源存储在更接近用户的位置,缩短到服务器的往返行程,加快页面加载时间来解决性能问题.WPO解决方案,如Radware的FastView,则在前端进行性能提升处理,使页面更有效地呈现在浏览器 ...
- label 赋值 , 隐藏 , 显示
<label name='by_stages_number' id='by_stages_number'></label> document.getElementById(&q ...
- 常用代码之三:jQuery为按钮绑定事件的代码
如题,比如有一个按钮:<input type='button' class='btn-text' id ='addHtml' value='新增' /> 为它添加onclick事件的代码: ...
- spring 项目中使用 hibernate validator验证输入参数
1 hibernate validator 官方文档:https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_si ...
- Mac笔记本安装mysql
在浏览器当中输入地址:dev.mysql.com/downloads/mysql/,如下图所示: 进入以下界面,直接点击下面位置 ,选择跳过登录,点过这后直接下载,如下图所示: 下载完成后, ...
- 腾讯企业邮箱SMTP-邮件发送失败异常:“ SMTPSendFailedException:501 ϵͳÒÑÇ¿ÖÆ¿ªÆôÕʺÅÉý¼¶ÉèÖã¬ÇëµÇ¼e
这里我们在报警发送邮件用的是腾讯的企业邮箱,突然这两天没有报警邮件,很是奇怪 发送邮件报错 SMTP-邮件发送失败异常:“ SMTPSendFailedException:501 ϵͳÒÑÇ¿ÖÆ ...
- ELK 的插件安装(head)
这里我装了一个head插件和kopf的插件 ./plugin install mobz/elasticsearch-head ./plugin install lmenezes/elasticsear ...