码迷,mamicode.com
首页 > 编程语言 > 详细

python nose测试框架全面介绍十---用例的跳过

时间:2018-06-19 21:32:11      阅读:684      评论:0      收藏:0      [点我收藏+]

标签:全面   装饰器   pos   method   and   htm   rdo   测试框架   相关   

  又来写nose了,这次主要介绍nose中的用例跳过应用,之前也有介绍,见python nose测试框架全面介绍四,但介绍的不详细。下面详细解析下

nose自带的SkipTest

   先看看nose自带的SkipTest典型应用

   应用一:

‘‘‘
@auth:hu
’‘‘
from nose.plugins.skip import SkipTest
@attr(mode=1) 
def test_learn_1():
    raise SkipTest

但这种SkipTest在实际的日志中没有显示Skip关键字

应用二:

如果想要在执行用例前判断相关字雄姿英发再进行用例跳过,如下

‘‘‘

@author: huzq
‘‘‘
import nose
import  nose.plugins.multiprocess
from testtools import TestCase
from nose import SkipTest
from nose.plugins.skip import Skip
import unittest


class TestClass():
 
    
    
    
    def setUp(self):
        print "MyTestClass setup"
        if "xxx" in "qqqq":
            raise SkipTest("adfdfd")
        

   
    def Testfunc1(self):
        print "this is Testfunc01"
        

每个用例前都会进行判断,并进行跳过操作

应用三:

可用觉得写在代码中太麻烦,SkipTest也可以当装饰器来进行,如下

‘‘‘
@author: huzq
‘‘‘
import nose
import  nose.plugins.multiprocess
from testtools import TestCase
from nose import SkipTest
from nose.plugins.skip import Skip
import unittest


class TestClass():
  
    
    @classmethod
    def setUpClass(self):
        print "xxxxxx"

    
    def setUp(self):
        print "MyTestClass setup"
        

    def tearDown(self):
        print "MyTestClass teardown"
        
    @SkipTest
    def Testfunc1(self):
        print "this is Testfunc01"
        

要注意的时,如果用装饰器形式,SkipTest后不能接具体原因,如果要接具体原因,只能用unittest的方法写,如下

@unittest.skip("I don‘t want to run this case.")

 

SkipTest可放在SetUpclass、SetUp、Test中

python nose测试框架全面介绍十---用例的跳过

标签:全面   装饰器   pos   method   and   htm   rdo   测试框架   相关   

原文地址:https://www.cnblogs.com/landhu/p/9200969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!