如何跳过装饰课的鼻子测试鼻子.plugins.attrib.attr在sh中

2024-05-18 11:41:50 发布

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

跳过nosetests的类装饰器可以写如下:

from nose.plugins.attrib import attr

@attr(speed='slow')
class MyTestCase:
    def test_long_integration(self):
        pass
    def test_end_to_end_something(self):
        pass

根据文档,“在Python2.6及更高版本中,@attr可以在一个类上同时设置所有测试方法的属性”

我找不到测试代码的方法。跑步

^{pr2}$

没用。任何帮助都将不胜感激。提前感谢:)


Tags: fromtestimportselfdefplugins装饰pass
1条回答
网友
1楼 · 发布于 2024-05-18 11:41:50

你失踪了unittest.TestCase测试的父类,即:

from unittest import TestCase
from nose.plugins.attrib import attr

@attr(speed='slow')
class MyTestCase(TestCase):
    def test_long_integration(self):
        pass
    def test_end_to_end_something(self):
        pass

class MyOtherTestCase(TestCase):
    def test_super_long_integration(self):
        pass

您的命令应根据属性选择测试,而不是跳过它们:

^{pr2}$

如果您想进行奇特的测试选择,可以使用“-A”属性并使用完整的python语法:

$ nosetests ss_test.py -A "speed=='slow'" -v
test_end_to_end_something (ss_test.MyTestCase) ... ok
test_long_integration (ss_test.MyTestCase) ... ok

                                   
Ran 2 tests in 0.003s

OK

以下是如何跳过慢速测试:

$ nosetests ss_test.py -A "speed!='slow'" -v
test_super_long_integration (ss_test.MyOtherTestCase) ... ok

                                   
Ran 1 test in 0.003s

OK

相关问题 更多 >