所以我有一个包含验收测试子目录的目录。 我的大多数测试彼此之间没有依赖关系,除了一套测试之外。 有没有一种方法可以告诉 Nose 何时到达此类以按顺序执行测试。然后,一旦它到达下一个类,再次启用多重处理? 这与此测试套件中的固定装置无关,它们根本无法同时运行。他们正在执行的 API 会影响同时运行的其他测试。
提前致谢。
最佳答案
我会用 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
关于Python Nosetest 多处理在类/包级别启用和禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35343440/