【问题标题】:Python Nosetest multi-processing enable and disable at Class/Package levelPython Nosetest 多处理在类/包级别启用和禁用
【发布时间】:2016-02-11 15:30:13
【问题描述】:

所以我有一个包含验收测试子目录的目录。 我的大多数测试都没有相互依赖关系,只需要一个套件。 有没有一种方法可以告诉鼻子何时到达此类以按顺序执行测试。那么一旦它到达下一个类以再次启用多处理? 这与该测试套件中的固定装置无关,它们根本无法同时运行。他们正在执行影响同时运行的其他测试的 API。

提前致谢。

【问题讨论】:

    标签: python multiprocessing automated-tests nose


    【解决方案1】:

    我会使用nose attribute 插件来装饰需要明确禁用多处理的测试并运行两个nose 命令:一个启用多处理,不包括敏感测试,另一个禁用多处理,仅包括敏感测试。您将不得不依赖 CI 框架来结合测试结果。比如:

    from unittest import TestCase
    from nose.plugins.attrib import attr
    
    @attr('sequential')
    class MySequentialTestCase(TestCase):
        def test_in_seq_1(self):
            pass
        def test_in_seq_2(self):
            pass
    
    class MyMultiprocessingTestCase(TestCase):
        def test_in_parallel_1(self):
            pass
        def test_in_parallel_2(self):
            pass
    

    然后像这样运行它:

    > nosetests -a '!sequential' --processes=10
    test_in_parallel_1 (ms_test.MyMultiprocessingTestCase) ... ok
    test_in_parallel_2 (ms_test.MyMultiprocessingTestCase) ... ok
    
    ----------------------------------------------------------------------
    Ran 2 tests in 0.071s
    
    OK
    > nosetests -a sequential
    test_in_seq_1 (ms_test.MySequentialTestCase) ... ok
    test_in_seq_2 (ms_test.MySequentialTestCase) ... ok
    
    ----------------------------------------------------------------------
    Ran 2 tests in 0.000s
    
    OK
    

    【讨论】:

    • 干杯@Oleksiy。没有意识到 attr 插件在类级别上工作。
    猜你喜欢
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    相关资源
    最近更新 更多