2

I would like to get some help for running multiple python test cases in parallel using multiprocessing module. I have created a class FooTest with 10 test cases in it (testA, testB...). There is a test case test_foo outside the class.

How can I run all the test cases in parallel using python multiprocessing module? Thanks for the help.

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)

1 Answer 1

6

According to nose documentation, which you can also get by running nosetests --help:

--processes=NUM Spread test run among this many processes. Set a number equal to the number of processors or cores in your machine for best results. Pass a negative number to have the number of processes automatically set to the number of cores. Passing 0 means to disable parallel testing. Default is 0 unless NOSE_PROCESSES is set. [NOSE_PROCESSES]

So just run nosetests --processes=-1 to run your tests in parallel using all the cores on your machine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.