Python Nosetest 多处理在 Class/Package 级别启用和禁用

Python Nosetest multi-processing enable and disable at Class/Package level

所以我有一个包含验收测试子目录的目录。 我的大部分测试都没有相互依赖关系,期望一个套件。 有没有一种方法可以让 nose 在到达 class 时告诉它按顺序执行测试。然后一旦它命中下一个 class 再次启用多处理? 这与此测试套件中的固定装置无关,它们根本无法 运行 同时进行。他们正在执行同时影响其他测试的 API 运行ning。

提前致谢。

我会使用 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