【问题标题】:How to skip nosetests of class decorated with nose.plugins.attrib.attr in shell如何在 shell 中跳过用nose.plugins.attrib.attr 装饰的类的鼻子测试
【发布时间】:2014-09-18 09:10:38
【问题描述】:

跳过鼻子测试的类装饰器可以写成如下:

从nose.plugins.attrib 导入属性 @attr(速度='慢') MyTestCase 类: def test_long_integration(self): 经过 def test_end_to_end_something(self): 经过

根据文档,“在 Python 2.6 及更高版本中,@attr 可用于一个类以一次设置其所有测试方法的属性”

我找不到测试代码的方法。运行

nosetests -a speed=slow

没有帮助。任何帮助将不胜感激。在此先感谢:)

【问题讨论】:

    标签: python nose


    【解决方案1】:

    您的测试缺少 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
    

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

    $ 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.004s
    
    OK
    

    如果你想做花哨的测试选择,你可以使用“-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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多