转载自:
https://blog.youkuaiyun.com/wsbl52006/article/details/88978456
很多时候我们写的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
---------------------