很多时候我们写的case会非常多,通常会对用例的重要程度做一些分级,比如主流程用例、次要流程用例之类的
通过nosetest -h 我们了解到有一个 -a 参数可以达到这个目的
-a ATTR, --attr=ATTR Run only tests that have attributes specified by ATTR
[NOSE_ATTR]
接着上次的测试类 TestClass.py
from nose.plugins.attrib import attr
class TestClass():
def setUp(self):
print ("MyTestClass setup")
def tearDown(self):
print ("MyTestClass teardown")
def Testfunc1(self):
print ("this is Testfunc1")
@attr(tag='main')
def test_func2(self):
print ("this is test_func2")
def Testfunc3(self):
print ("this is Testfunc3")
def test_func4(self):
print ("this is test_func4")
在命令行执行时增加-a参数: nosetests -s -a tag TestClass
执行结果如下:
MyTestClass setup
this is test_func2
MyTestClass teardown
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
本文介绍如何使用Nosetest框架的-a参数来筛选带有特定属性标记的测试用例进行执行,通过实例演示了如何为测试方法添加属性标签,并在命令行中指定这些标签来运行相应的测试。
90

被折叠的 条评论
为什么被折叠?



