網(wǎng)站首頁 編程語言 正文
前言
如果想分布式執(zhí)行用例,用例設(shè)計必須遵循以下原則:
1、用例之間都是獨立的,
2、用例a不要去依賴用例b
3、用例執(zhí)行沒先后順序,
4、隨機都能執(zhí)行每個用例都能獨立運行成功每個用例都能重復(fù)運行,不影響其它用例
這跟就我們平常多個人工測試一樣,用例都是獨立的,可以隨機分配不同人員執(zhí)行,互相不依賴,用例之間也不存在先后順序
一、pytest-parallel
安裝:pip install pytest-parallel
常用參數(shù)配置:
- --workers=n:多進程運行需要加此參數(shù), n是進程數(shù)。默認為1
- --tests-per-worker=n:多線程需要添加此參數(shù),n是線程數(shù)
如果兩個參數(shù)都配置了,就是進程并行,每個進程最多n個線程,總線程數(shù):進程數(shù)*線程數(shù)
注意:在windows上進程數(shù)永遠為1。
需要使用 if name == “main”:,在dos中運行會報錯
#!/usr/bin/env python # _*_ coding: utf-8 _*_ # @project : API_Service # @File : test_1.py # @Date : 2021/6/15 3:07 下午 # @Author : 李文良 # demo: import pytest def test_01(): print('測試用例1操作') def test_02(): print('測試用例2操作') def test_03(): print('測試用例3操作') def test_04(): print('測試用例4操作') def test_05(): print('測試用例5操作') def test_06(): print('測試用例6操作') def test_07(): print('測試用例7操作') def test_08(): print('測試用例8操作') if __name__ == "__main__": pytest.main(["-s", "test_1.py",'--workers=2', '--tests-per-worker=4'])
二、pytest-xdist
安裝:pip install pytest-xdist
不支持多線程
常用參數(shù)配置:
- -n=*:*代表進程數(shù)
多cpu并行執(zhí)行用例,直接加個-n參數(shù)即可,后面num參數(shù)就是并行數(shù)量,比如num設(shè)置為3
- -n auto 自動偵測系統(tǒng)里的CPU數(shù)目
- -n num 指定運行測試的處理器進程數(shù)
三、對比說明
pytest-parallel比pytst-xdist相對好用,功能支持多。
pytst-xdist不支持多線程,而pytest-parallel支持python3.6及以上版本,如果想做多進程并發(fā)在linux或者mac上做,在Windows上不起作用(Workers=1),如果做多線程linux/mac/windows平臺都支持,進程數(shù)為workers的值。
pytest-parallel常用配置命令如下
- –workers (optional) *:多進程運行需要加此參數(shù), *是進程數(shù)。默認為1。
- –tests-per-worker (optional) *:多線程運行, *是每個worker運行的最大并發(fā)線程數(shù)。默認為1
pytest test.py --workers 3:3個進程運行
pytest test.py --tests-per-worker 4:4個線程運行
pytest test.py --workers 2 --tests-per-worker 4:2個進程并行,且每個進程最多4個線程運行,即總共最多8個線程運行。
四、特別注意
1、pytest-parallel的workers參數(shù)在windows系統(tǒng)下永遠是1,在linux和mac下可以取不同值。
2、pytest-parallel加了多線程處理后,最后執(zhí)行時間是運行時間最長的線程的時間。
3、在windows下想用多進程的選pytst-xdist; 想用多線程的選pytest-parallel
原文鏈接:https://blog.csdn.net/weixin_44275820/article/details/112169328
相關(guān)推薦
- 2022-05-23 Jenkins實現(xiàn)集群化管理以及流水線項目配置_nginx
- 2022-08-31 Flask接收上傳圖片方法實現(xiàn)_python
- 2022-12-15 深入了解Golang中的格式化輸出_Golang
- 2022-08-15 關(guān)于PL/SQL進行更新操作時卡死的解決辦法
- 2022-11-22 Kotlin?by關(guān)鍵字作用及使用介紹_Android
- 2023-07-06 mac配置idea自帶的maven3環(huán)境變量
- 2022-08-05 C語言示例講解if?else語句的用法_C 語言
- 2022-04-23 C語言Static?關(guān)鍵字解析_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支