Python Nosetest 多处理在类/包级别启用和禁用

标签 python multiprocessing automated-tests nose

所以我有一个包含验收测试子目录的目录。 我的大多数测试彼此之间没有依赖关系,除了一套测试之外。 有没有一种方法可以告诉 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/

相关文章:

python - 使用 Python 和 selenium 从 Tweet 中提取 YouTube 链接

android - 葫芦安卓 : Check if a button is present and enabled

internet-explorer - Internet Explorer 的测试自动化

windows - "system"的 Perl Windows 替代品(打开多个进程)

python - 如何根据工作结果向正在运行的多处理池添加额外任务?

testing - Testcafe 测试未在 MacBook Big Sur 上执行,带有 UnableToAccessScreenRecordingAPIError :

python - 在循环中的同一行上打印多个字符串

python - 在 Python 中重现涉及 for 循环的 MATLAB 代码时出现问题

python - Lucene:返回短语文档出现的最快方法?

python - 从 Process() 设置时,全局变量无法正确保存