有没有办法控制pytest的方式
我有以下目录布局:
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__)])
我遇到的问题是我想并行执行'测试套件',即我想要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,))
pytest-xdist目前没有“每个文件”或“每个测试套件”的分布。 实际上,如果每个文件分发(例如文件中的测试一次只能由最多一个工作人员执行)已经可以帮助您的用例,我鼓励您在https:/ /bitbucket.org/hpk42/pytest/issues?status=new&status=open并链接回你在这里的好解释。
欢呼声,霍尔格
链接地址: http://www.djcxy.com/p/50791.html上一篇: Is there a way to control how pytest
下一篇: Spawning multiple browsers from Selenium RC utilizing Python
