我有以下的目录布局:有没有办法控制pytest-xdist如何并行运行测试?
runner.py
lib/
tests/
testsuite1/
testsuite1.py
testsuite2/
testsuite2.py
testsuite3/
testsuite3.py
testsuite4/
testsuite4.py
的测试套件*的.py模块的格式如下:
import pytest class testsomething: def setup_class(self): ''' do some setup ''' # Do some setup stuff here def teardown_class(self): '''' do some teardown''' # Do some teardown stuff here def test1(self): # Do some test1 related stuff def test2(self): # Do some test2 related stuff .... .... .... def test40(self): # Do some test40 related stuff if __name__=='__main()__' pytest.main(args=[os.path.abspath(__file__)])
我的问题是,我想执行“测试套件”也就是说,我想要testsuite1,testsuite2,testsuite3和testsuite4并行开始执行,但是测试套件中的单个测试需要连续执行。
当我使用py.test中的'xdist'插件并使用'py.test -n 4'启动测试时,py.test正在收集所有测试并随机对4名工作人员之间的测试进行负载平衡。这导致'test_item.py'模块中的每次测试都会执行'setup_class'方法(这违背了我的目的,我希望setup_class只在每个类中执行一次,然后在那里串行执行测试)。
基本上我想要执行的样子是:
worker1: executes all tests in testsuite1.py serially worker2: executes all tests in testsuite2.py serially worker3: executes all tests in testsuite3.py serially worker4: executes all tests in testsuite4.py serially
而worker1, worker2, worker3 and worker4
并行获执行。
有没有办法在'pytest-xidst'框架中实现这一点?
,我能想到的唯一的选择是揭开序幕不同的进程runner.py内单独执行每个测试套件:
def test_execute_func(testsuite_path): subprocess.process('py.test %s' % testsuite_path) if __name__=='__main__': #Gather all the testsuite names for each testsuite: multiprocessing.Process(test_execute_func,(testsuite_path,))
对于任何人查看这篇文章,知道如果任何问题已经打开,问题是:https://github.com/pytest-dev/pytest/issues/175和https:// github.com/pytest-dev/pytest/issues/738 – 2015-10-06 15:55:42