我有以下的目錄佈局:有沒有辦法控制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