首页 > 编程语言 > 详细

python nose测试框架全面介绍五--attr介绍

时间:2017-11-18 12:26:21      阅读:931      评论:0      收藏:0      [点我收藏+]

之前写了一系列nose框架的,这篇介绍下attr tag

在nose框架中attr用来标识用例,使得在运行时可以通过标识来执行用例,之前在nose测试框架全面介绍四中有说明,但没有说明清楚,这里再总结下。

一、标识方式

   标识方式有二种:

    1、方式一(不太好用)

       

def test_learn_1():
    u‘‘‘测试‘‘‘
    print xxx
    eq_(7, 7, msg=u"错误")
    
test_learn_1.slow=1

 2、使用attr装饰器

from nose.plugins.attrib import attr
@attr(mode=2) 
def test_lean_2():
    u‘‘‘测试失败‘‘‘
    try:
        print "test_learn_2"
        ok_(4==3,msg="xxx")
        print sys._getframe().f_code.co_name
    except Exception:
        print sys._getframe().f_code.co_name

或直接attr

@attr(afdfd) 
def test_lean_3():
    u‘‘‘测试成功‘‘‘
    pass

 

二、运行

运行方式如下:

使用-a或者--attr来标识

nosetests -a mode=2

表示只运行标识中mode等于2的

nosetests -a mode=2,afdfd

表示运行同时包含标识中mode等于2及标识中有afdfd的用例,注意,是同时包含

nosetests -a mode=2 -a safdfd

表示运行包含标识mode等于2或者标识中safdfd的用例,注意,是或者的关系

同样,-a后面还可以接正则表达式来运行,不过,我目前用的很少,基本上没用到,也介绍下吧

注意,要使用这种方式的话,要用-A或--eval-attr参数来标识

nosetests -A "not afdfd" 
nosetests -A "(mode > 5) and not afdfd"

 转载请标明来源:landhu.cnblogs.com

python nose测试框架全面介绍五--attr介绍

原文:http://www.cnblogs.com/landhu/p/7856135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!