Python鼻子注释

2024-09-25 00:25:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用注释@SmokeTest@LoadTest@RegressionTest或{}来标记每个单独的测试用例。在

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

  1. 烟度试验
  2. 负荷试验
  3. 回归
  4. 长期运行试验 我想为每个单独的测试用例添加标签请提供您的建议。 http://pythontesting.net/framework/nose/nose-introduction/

Tags: 标记httpnet测试用例标签类别建议nose
3条回答

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

使用@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...

运行方式:

^{pr2}$

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

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

运行方式:

nosetests -a priority=sanity

使用@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...

然后运行为

^{pr2}$

相关问题 更多 >