python并发执行测试_python – 有没有办法控制pytest-xdist如何并行运行测试?

我有以下目录布局:

runner.py

lib/

tests/

testsuite1/

testsuite1.py

testsuite2/

testsuite2.py

testsuite3/

testsuite3.py

testsuite4/

testsuite4.py

testsuite * .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__)])

我所遇到的问题是我想并行执行’testsuites’,即我想要testsuite1,testsuite2,testsuite3和testsuite4并行启动执行,而是需要连续执行测试工作中的单独测试。

当我使用py.test中的’xdist’插件,并使用’py.test -n 4’启动测试时,py.test正在收集所有的测试,并随机地在4个工作人员之间平衡测试。这样就可以在“testsuitex.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和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,))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值