首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在并行python中运行测试用例

在并行python中运行测试用例
EN

Stack Overflow用户
提问于 2015-12-20 14:22:56
回答 1查看 3.5K关注 0票数 2

我希望获得一些帮助,以便使用多处理模块并行运行多个python测试用例。我创建了一个类FooTest,其中包含10个测试用例(testA,testB.)。在类之外有一个测试用例test_foo。

如何使用python多处理模块并行运行所有测试用例?谢谢你的帮助。

代码语言:javascript
运行
复制
import unittest
import time

def setUp():
    print "module setup"

def test_foo():
    pass

class FooTest(unittest.TestCase):

    # preparing to test
    def setUp(self):
        """ Setting up for the test """
        print "FooTest:setUp_:begin"

    # ending the test
    def tearDown(self):
        """Cleaning up after the test"""
        print "FooTest:tearDown_:begin"

    # test routine A
    def testA(self):
        """Test routine A"""
        print "FooTest:testA"
        time.sleep(2)

    # test routine B
    def testB(self):
        """Test routine B"""
        print "FooTest:testB"

    # test routine C
    def testC(self):
        """Test routine C"""
        print "FooTest:testC"

    # test routine D
    def testD(self):
        """Test routine D"""
        print "FooTest:testD"

    # test routine E
    def testE(self):
        """Test routine E"""
        print "FooTest:testE"
        time.sleep(2)

    # test routine F
    def testF(self):
        """Test routine F"""
        print "FooTest:testF"

    # test routine G
    def testG(self):
        """Test routine G"""
        print "FooTest:testG"

    # test routine H
    def testH(self):
        """Test routine H"""
        print "FooTest:testH"

    # test routine I
    def testI(self):
        """Test routine I"""
        print "FooTest:testI"

    # test routine J
    def testJ(self):
        """Test routine J"""
        print "FooTest:testJ"
        time.sleep(2)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-21 05:50:01

根据鼻文件,您也可以通过运行nosetests --help来获得它

-进程=在这许多进程之间运行NUM扩展测试。设置一个与计算机中的处理器或核数相等的数字,以获得最佳结果。传递一个负数,使进程数自动设置为核数。通过0意味着禁用并行测试。除非设置了NOSE_PROCESSES,否则默认值为0。NOSE_PROCESSES

因此,只需运行nosetests --processes=-1,使用机器上的所有核心并行运行您的测试。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34381970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档