python测试工具nosetests
今天在github上找东西,找到个工具是python写的,但是需要安装nosetests,因此了解了下nosetests
python除了unittest,还有nosetests,使用更快捷
nosetests的口号:
nose extends unittest to make testing easier
特点:
自动发现测试用例(包含[Tt]est文件以及文件包中包含test的函数)
如:以test开头的文件;以test开头的函数或方法;以Test开头的类
nose自动收集单元测试,会自动识别源代码文件、目录或包中的测试用例,任何符合正则表达式:(?:^|[b_.-])[Tt]est的类、函数、文件或目录,以及TestCase的子类都会被识别并执行,匹配成功的包、任何python的源文件都会被当做测试用例。
1.安装
pip install nose
测试安装是否成功
nosetests -V

2.使用
常用命令
nosetests –h 查看所有nose相关命令
nosetests –s 执行并捕获输出
nosetests –with-xunit 输出xml结果报告
nosetests -w 查看指定目录下的
nosetests -v 查看nose的运行信息和调试信息
nose支持setup和teardown函数,在测试用例的前后执行。作用域:
1、package
可以在__init__.py中定义
setup方法名可以是setup, setup_package, setUp, or setUpPackage
teardown方法名可以是teardown, teardown_package, tearDown or tearDownPackage。比如定义数据库的连接和释放
2、module
在模块内定义setup,setup_module, setUp or setUpModule,和/或teardown,teardown_module, or tearDownModule
3、class
4、function
任何符合正则的函数都会被包装成FunctionTestCase

testcase下面test.py
def Testfunc():
a = 1
b = 2
assert a == b
运行测试
(1)自动发现和执行
进入testcase目录执行
nosetests -v

(2)编码实现测试用例的执行
在main.py所在的目录
main.py
import nose
result = nose.run()
print(result)
执行
python main.py

3.测试用例
(1)函数形式
def test_1():
print("test_1")
pass def test_2():
print("test_2") def test_3():
print("test_3")
def setUp():
print "test setUp" def tearDown():
print "test teardown" test_1.teardown=test_2.teardown= tearDown
运行某个文件
nosetests test1.py

nosetests -s

nosetests -s test1.test_3

test_1.teardown=test_2.teardown= tearDown,说明在运行完成后就执行tearDown操作
(2)类形式
test/test2下新建test2.py
class Testclass:
def __init__(self):
pass
def testfunc1(self):
print 'this is case1'
def testfunc2(self):
print 'this is case2'
def testfunc3(self):
print 'this is case3'
执行
nosetests -s

执行
nosetests -v

在test目录执行
nosetests -v -s test2

nosetests -v -s test2.test2

nosetests -v -s test2.test2:Testclass.testfunc1

nosetests -v -s test2.test2:Testclass.testfunc1

nosetests -s test2.test2:Testclass.testfunc1

补充:
在输出文件中填加testid的显示 nosetests -v --with-id

通过id,自定义要运行的测试用例 nosetests -v --with-id id号

python测试工具nosetests的更多相关文章
- Python测试工具——nose
1.nose 特点: a) 自动发现测试用例(包含[Tt]est文件以及文件包中包含test的函数) b) 以test开头的文件 c) 以test开头的 ...
- python测试工具
https://wiki.python.org/moin/PythonTestingToolsTaxonomy mac pip安装 https://blog.csdn.net/ywj_486/arti ...
- python测试框架&&数据生成&&工具最全资源汇总
xUnit frameworks 单元测试框架frameworks 框架unittest - python自带的单元测试库,开箱即用unittest2 - 加强版的单元测试框架,适用于Python 2 ...
- 收藏清单: python测试框架最全资源汇总
xUnit frameworks 单元测试框架 frameworks 框架 unittest - python自带的单元测试库,开箱即用 unittest2 - 加强版的单元测试框架,适用于Pytho ...
- 转 python测试框架最全资源汇总
转自: http://www.testclass.net/list/python_list_1/ xUnit frameworks(单元测试框架) frameworks 框架 unittest - p ...
- Python渗透测试工具合集
摘自:http://www.freebuf.com/tools/94777.html 如果你热爱漏洞研究.逆向工程或者渗透测试,我强烈推荐你使用 Python 作为编程语言.它包含大量实用的库和工具, ...
- python的web压力测试工具-pylot安装使用
http://blog.csdn.net/chenggong2dm/article/details/10106517 pylot是python编写的一款web压力测试工具.使用比较简单.而且测试结果相 ...
- 使用python实现测试工具(一)
本系列教程我们将使用python实现一些简单的测试工具,为了尽可能的简单,我们的工具以命令行工具为主. 本系列教程使用的python版本是3.6.3. 背景 这一节我们实现简单的命令行发送get请求的 ...
- Python测试 ——开发工具库
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
随机推荐
- EasyUI之dataGrid的行内编辑
$(function () { var datagrid; //定义全局变量datagrid var editRow = undefined; //定义全局变量:当前编辑的行 datagrid = T ...
- python 查询文件修改python lib 库文件
运行code import os, time import sys import re def search(path, name): for root, dirs, files in os.walk ...
- c#语言学习笔记(1)
环境:VS Express 2013 for Desktop 也可以vs社区版,不过学习的话,Express本版做一些小的上位机工具应该是够用了 学习的网站:https://www.runoob.co ...
- linux 判空处理
linux在进行判空是一个经常要用到的操作,可以使用如下方式: 变量通过" "引号引起来 if [ ! -n "$filename" ];then echo & ...
- ccf算法模板
bellman ford 算法求最短路径 #include <iostream> using namespace std; ; ; // 边, typedef struct Edge{ i ...
- LeetCode 1143. Longest Common Subsequence
原题链接在这里:https://leetcode.com/problems/longest-common-subsequence/ 题目: Given two strings text1 and te ...
- git的搭建和使用
目录: 1.git与github介绍2.下载安装Git-20-64-bit.exe3.Git常用命令 git与github介绍 Git是什么 Git是一个开源的[分布式][版本控制系统],用于敏捷高效 ...
- FOREIGN KEY 外键约束; UNIQUE和PRIMARY KEY 主键约束、CREATE INDEX建立索引的使用
1)foreign key 是个约束,意思是说如果你给A字段设置了外键约束,以后你要往A字段插入数据,这个数据一定是要在foreign key 后面跟的那个字段中存在的值.这个的意义就是约束了数据的完 ...
- HAProxy+Keepalived高可用负载均衡
一 基础准备 1.1 部署环境及说明 系统OS:CentOS 6.8 64位 HAProxy软件:HA-Proxy version 1.5.18 Keepalived软件:keepalived-1.3 ...
- 记录linux上mongo迁移使用的命令
首先mongodb的文件路径必须在系统盘,这里是 这里安装路径 /usr/mongodb/bin 一般迁移的只是db文件夹和log文件 看配置文件内容 port=27017 #端口 dbpath=/d ...