1、pytest-parallel
安裝: pip install pytest-parallel
常用參數配置:
--workers=n:多進程運行需要加此參數, n是進程數。默認為1
--tests-per-worker=n:多線程需要添加此參數,n是線程數
如果兩個參數都配置了,就是進程並行,每個進程最多n個線程,總線程數:進程數*線程數
注意:在windows上進程數永遠為1。
需要使用 if __name__ == "__main__":,在dos中運行會報錯
實現:
import pytest def test_03(start,open_web1): print('測試用例3操作') def test_04(start,open_web1): print('測試用例4操作') if __name__ == "__main__": pytest.main(["-s", "test_1.py",'--workers=2', '--tests-per-worker=4'])
2、pytest-xdist
安裝:pip install pytest-xdist
不支持多線程
常用參數配置:
-n=*:*代表進程數
注意:
1、pytest-parallel加了多線程處理后,最后執行時間是運行時間最長的線程的時間。
2、在windows下想用多進程的選pytst-xdist; 想用多線程的選pytest-parallel