如何在muticore机器上加速python单元测试?

sor*_*rin 13 python performance multithreading unit-testing multicore

我正在使用python unittest来测试其他一些外部应用程序,但是需要花费太多时间来逐个运行测试.

我想知道如何通过使用多核的功能来加速这个过程.我可以调整unittest来并行执行测试吗?怎么样?

这个问题不能python GIL限制,因为事实上不是python代码需要时间,而是我执行的外部应用程序,目前通过os.system().

Vin*_*jip 6

如果你的测试是不是太参与,您可以使用运行它们py.test具有分布式测试的支持.如果您没有在Windows上运行,那么鼻子也可能适合您.


Joe*_*Joe 5

所述testtools包是支持同时运行的测试单元测试的延伸.它可以与继承的旧测试类一起使用unittest.TestCase.

例如:

import unittest
import testtools

class MyTester(unittest.TestCase):
    # Tests...

suite = unittest.TestLoader().loadTestsFromTestCase(MyTester)
concurrent_suite = testtools.ConcurrentStreamTestSuite(lambda: ((case, None) for case in suite))
concurrent_suite.run(testtools.StreamResult())
Run Code Online (Sandbox Code Playgroud)

  • 刚刚用 python 2.7 对此进行了测试,没有任何变化,我的单元测试仍在串行运行。 (2认同)