nose
nose 项目 菠菜源码搭建Q2152876294 论坛:diguaym.com是于 2005 年发布的,也就是 py.test 改名后的一年。它是由 Jason Pellerin 编写的,支持与 py.test 相同的测试习惯做法,但是这个包更容易安装和维护。尽管 py.test 在某些方面有所进步,目前也很容易安装,但是 nose 仍然保持了易用性方面的声誉。
nose不是python自带模块,需要用pip安装
pip install nose
1
nose相关执行命令:
1、 nosetests –h查看所有nose相关命令
2、 nosetests –s执行并捕获输出
3、 nosetests –with-xunit输出xml结果报告
4、 nosetests -v: 查看nose的运行信息和调试信息
5、 nosetests -w 目录:指定一个目录运行测试
nose 特点:
a) 自动发现测试用例(包含[Tt]est文件以及文件包中包含test的函数)
b) 以test开头的文件
c) 以test开头的函数或方法
d) 以Test开头的类
经过研究发现,nose会自动识别[Tt]est的类、函数、文件或目录,以及TestCase的子类,匹配成功的包、任何python的源文件都会被当做测试用例。
example1.py
class Testclass:
def __init__(self):
pass
def setup(self):
print 'start'
def teardown(self):
print 'stop'
def testfunc1(self):
print 'this is case1'
def testfunc2(self):
print 'this is case2'
def testfunc3(self):
print 'this is case3'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
这里写图片描述
example2.py
encoding:utf-8
import testtools
class TestSetUp(testtools.TestCase):
@classmethod
def setUp(cls):
print "setUp running"
@classmethod
def setUpClass(cls):
print "setUpClass running"
@classmethod
def tearDown(cls):
print "teardown