Python鼻子注释

问题描述 投票:0回答:3

我想用注释@SmokeTest@LoadTest @RegressionTest@LongRunningTest标记每个单独的测试用例。

是否可以使用提供注释的Python鼻子将每个测试用例分类为以下类别之一?

  1. 烟雾测试
  2. 负载测试
  3. 回归
  4. 长时间运行测试我想为每个测试用例添加标签,请提供您的建议。 http://pythontesting.net/framework/nose/nose-introduction/
python nose
3个回答
2
投票

使用@attr添加属性。如果你想运行整个类,可以为类设置@attr,方法与下面相同

参考:http://nose.readthedocs.org/en/latest/plugins/attrib.html

from nose.plugins.attrib import attr

@attr('smoke')
def test_awesome_1():
    # your test...
@attr('load')
def test_awesome_2():
    # your test...
@attr('regression')
def test_awesome_3():
    # your test...
@attr('regression')
def test_awesome_4():
    # your test...

然后运行它

nosetests -a 'smoke'            #Runs test_awesome_1 only
nosetests -a 'load'             #Runs test_awesome_2 only
nosetests -a 'regression'       #Runs test_awesome_3 and test_awesome_4

1
投票

很难确切地说出你在问什么,但听起来你可能正在寻找the built-in nose plugin 'Attrib',它允许你为测试设置属性(并根据属性选择测试组)。


0
投票

使用@attr添加属性来标记测试用例和类,并带有注释:

from nose.plugins.attrib import attr

    @attr(priority='first')
    def test_support_1():
        #test details...

    @attr(priority='second')
    def test_support_2():
        #test details...

运行方式为:

nosetests -a priority=first
nosetests -a priority=second

在Python 2.6及更高版本中,可以在类上设置@attr,如下所示:

    @attr(priority='sanity')
    class MyTestCase:
       def test_support_1(self):
         pass
       def test_support_2(self):
         pass

运行方式为:

nosetests -a priority=sanity
© www.soinside.com 2019 - 2024. All rights reserved.