简体   繁体   中英

Python Nose tests from generator not running concurrently

Given the following:

from time import sleep

def runTest(a):
    sleep(1)
    assert a >= 0

def test_all():
    for i in range(5):
        yield (runTest, i)

I would expect the five tests to get run in parallel running with nosetests --processes=8 and thus run in approximately one second — however, it takes just over five seconds to run: they appear to be running sequentially and not concurrently.

According to the nose documentation, the multiprocess plugin has supported test generators (as the nose documentation calls them) since 1.1: I'm using nose 1.3.0 so it should be supported. Adding _multiprocess_can_split_ = True does make any difference, as one would expect, as fixtures are not used.

How do I get these five tests to run concurrently?

根据nase的作者的说法, 在邮件列表中 ,多进程插件不适用于1.3中的生成器( 一个已知的bug ),他建议坚持使用1.1(如果需要)。

You may try

from time import sleep
from multiprocessing import Process

def runTest(a):
    sleep(1)
    assert a >= 0

def test_all():
    for i in range(5):
        Process(target=(yield (runTest, i))).start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM