当前位置:网站首页>pytest接口自动化测试框架 | 多进程运行用例
pytest接口自动化测试框架 | 多进程运行用例
2022-07-23 12:18:00 【COCOgsta】
视频来源:B站《冒死上传!pytest接口自动化测试框架(基础理论到项目实战及二次开发)教学视频【软件测试】》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
附上汇总贴:pytest接口自动化测试框架 | 汇总_COCOgsta的博客-CSDN博客
安装pytest-xdist
pip install pytest-xdist
运行模式:
pytest -n NUMCPUS
import pytest
def test_case01():
assert 1==1
def test_case02():
assert 1 == 1
def test_case03():
assert 1 == 3
def test_case04():
assert 1 == 4
def test_case05():
assert 1 == 5
def test_case06():
assert 1 == 1
if __name__ == '__main__':
# 将测试发送到多个CPU
# pytest.main(["-n", "2", "test_many.py"])
# 使用与计算机具有的CPU内核一样多的进程
pytest.main(["-n", "auto", "test_many.py"])也是通过命令行执行生效
PS D:\SynologyDrive\CodeLearning\WIN\pytest\base_used> pytest .\test_fail2.py --maxfail 2
======================================================================================================== test session starts ========================================================================================================
platform win32 -- Python 3.6.6, pytest-7.0.1, pluggy-1.0.0
rootdir: D:\SynologyDrive\CodeLearning\WIN\pytest\base_used
plugins: allure-pytest-2.9.45, forked-1.4.0, html-3.1.1, metadata-1.11.0, ordering-0.6, rerunfailures-10.2, xdist-2.5.0
collected 3 items
test_fail2.py FF
============================================================================================================= FAILURES ==============================================================================================================
____________________________________________________________________________________________________________ test_fail01 ____________________________________________________________________________________________________________
def test_fail01():
print("第一次失败")
> assert 1==2
E assert 1 == 2
test_fail2.py:6: AssertionError
------------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------------
第一次失败
____________________________________________________________________________________________________________ test_fail02 ____________________________________________________________________________________________________________
def test_fail02():
print("第二次失败")
> assert 1 == 2
E assert 1 == 2
test_fail2.py:11: AssertionError
------------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------------
第二次失败
====================================================================================================== short test summary info ======================================================================================================
FAILED test_fail2.py::test_fail01 - assert 1 == 2
FAILED test_fail2.py::test_fail02 - assert 1 == 2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 2 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================================================= 2 failed in 0.09s =========================================================================================================
PS D:\SynologyDrive\CodeLearning\WIN\pytest\base_used>
PS D:\SynologyDrive\CodeLearning\WIN\pytest\base_used> pip install pytest-xdist
Requirement already satisfied: pytest-xdist in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (2.5.0)
Requirement already satisfied: pytest>=6.2.0 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest-xdist) (7.0.1)
Requirement already satisfied: execnet>=1.1 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest-xdist) (1.9.0)
Requirement already satisfied: pytest-forked in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest-xdist) (1.4.0)
Requirement already satisfied: colorama; sys_platform == "win32" in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (0.4.5)
Requirement already satisfied: importlib-metadata>=0.12; python_version < "3.8" in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (4.8.3)
Requirement already satisfied: attrs>=19.2.0 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (21.4.0)
Requirement already satisfied: atomicwrites>=1.0; sys_platform == "win32" in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (1.4.1)
Requirement already satisfied: tomli>=1.0.0 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (1.2.3)
Requirement already satisfied: pluggy<2.0,>=0.12 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (1.0.0)
Requirement already satisfied: py>=1.8.2 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (1.11.0)
Requirement already satisfied: iniconfig in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (1.1.1)
Requirement already satisfied: packaging in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from pytest>=6.2.0->pytest-xdist) (21.3)
Requirement already satisfied: zipp>=0.5 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest>=6.2.0->pytest-xdist) (3.6.0)
Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest>=6.2.0->p
ytest-xdist) (4.1.1)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\guoliang\appdata\local\programs\python\python36\lib\site-packages (from packaging->pytest>=6.2.0->pytest-xdist) (3.0.7)
You are using pip version 10.0.1, however version 21.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
PS D:\SynologyDrive\CodeLearning\WIN\pytest\base_used> pytest .\test_fail2.py -n=2
======================================================================================================== test session starts ========================================================================================================
platform win32 -- Python 3.6.6, pytest-7.0.1, pluggy-1.0.0
rootdir: D:\SynologyDrive\CodeLearning\WIN\pytest\base_used
plugins: allure-pytest-2.9.45, forked-1.4.0, html-3.1.1, metadata-1.11.0, ordering-0.6, rerunfailures-10.2, xdist-2.5.0
gw0 [3] / gw1 [3]
FF. [100%]
============================================================================================================= FAILURES ==============================================================================================================
____________________________________________________________________________________________________________ test_fail01 ____________________________________________________________________________________________________________
[gw0] win32 -- Python 3.6.6 c:\users\guoliang\appdata\local\programs\python\python36\python.exe
def test_fail01():
print("第一次失败")
> assert 1==2
E assert 1 == 2
test_fail2.py:6: AssertionError
------------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------------
第一次失败
____________________________________________________________________________________________________________ test_fail02 ____________________________________________________________________________________________________________
[gw1] win32 -- Python 3.6.6 c:\users\guoliang\appdata\local\programs\python\python36\python.exe
def test_fail02():
print("第二次失败")
> assert 1 == 2
E assert 1 == 2
test_fail2.py:11: AssertionError
------------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------------
第二次失败
====================================================================================================== short test summary info ======================================================================================================
FAILED test_fail2.py::test_fail01 - assert 1 == 2
FAILED test_fail2.py::test_fail02 - assert 1 == 2
==================================================================================================== 2 failed, 1 passed in 0.84s ====================================================================================================
PS D:\SynologyDrive\CodeLearning\WIN\pytest\base_used> pytest .\test_many.py -n=2
======================================================================================================== test session starts ========================================================================================================
platform win32 -- Python 3.6.6, pytest-7.0.1, pluggy-1.0.0
rootdir: D:\SynologyDrive\CodeLearning\WIN\pytest\base_used
plugins: allure-pytest-2.9.45, forked-1.4.0, html-3.1.1, metadata-1.11.0, ordering-0.6, rerunfailures-10.2, xdist-2.5.0
gw0 [6] / gw1 [6]
..FFF. [100%]
============================================================================================================= FAILURES ==============================================================================================================
____________________________________________________________________________________________________________ test_case03 ____________________________________________________________________________________________________________
[gw0] win32 -- Python 3.6.6 c:\users\guoliang\appdata\local\programs\python\python36\python.exe
def test_case03():
> assert 1 == 3
E assert 1 == 3
test_many.py:12: AssertionError
____________________________________________________________________________________________________________ test_case04 ____________________________________________________________________________________________________________
[gw1] win32 -- Python 3.6.6 c:\users\guoliang\appdata\local\programs\python\python36\python.exe
def test_case04():
> assert 1 == 4
E assert 1 == 4
test_many.py:16: AssertionError
____________________________________________________________________________________________________________ test_case05 ____________________________________________________________________________________________________________
[gw0] win32 -- Python 3.6.6 c:\users\guoliang\appdata\local\programs\python\python36\python.exe
def test_case05():
> assert 1 == 5
E assert 1 == 5
test_many.py:20: AssertionError
====================================================================================================== short test summary info ======================================================================================================
FAILED test_many.py::test_case03 - assert 1 == 3
FAILED test_many.py::test_case04 - assert 1 == 4
FAILED test_many.py::test_case05 - assert 1 == 5
==================================================================================================== 3 failed, 3 passed in 0.83s ====================================================================================================
PS D:\SynologyDrive\CodeLearning\WIN\pytest\base_used>
边栏推荐
- Talk about the memory layout of JVM
- 20220721挨揍内容
- Basic concept and deployment of kubernetes
- Bean Validation起源篇----01
- 黑马程序员-接口测试-四天学习接口测试-第三天-postman高级用法,newman例集导出导入,常用断言,断言json数据,工作原理,全局,环境变量,时间戳,请求前置脚本,关联,批量执行测试用例
- First hello of SOC_ World experiment
- High cost performance, high anti-interference touch IC that meets a variety of keys: vk3606d, vk3610i, vk3618i have high power voltage rejection ratio
- 大端模式和小端模式的记忆方法
- Squid 代理服务之透明代理服务器架构搭建
- Bean validation beginner ----02
猜你喜欢

VMWARE平台STS证书过期

Origin of bean validation ----01

Memory methods of big end mode and small end mode

MySQL - master-slave replication

C#中单例模式的实现

再获殊荣 | OpenSCA获选中国软博会“全球十大开源软件产品”

Bean Validation核心組件篇----04

How to choose fluorescent dyes in laser confocal

MySQL string sorted by numeric value

Bean Validation入门篇----02
随机推荐
Cover - computer knowledge guide
Why build a uilabel? (review liangya Technology)
Vrrp+mstp configuration details [Huawei ENSP experiment]
20220721挨揍内容
The difference between deadlock, hunger and dead cycle
nport串口服务器原理,MOXA串口服务器NPORT-5130详细配置
千万别让富坚义博看到这个
Cloud native (11) | kubernetes chapter kubernetes principle and installation
"1+1 > 10": potential combination of no code / low code and RPA Technology
知道为什么PCBA电路板会板翘吗?
FPGA-HLS-乘法器(流水线对比普通仿真)
Custom JSTL tag of JSP
黑马程序员-接口测试-四天学习接口测试-第三天-postman高级用法,newman例集导出导入,常用断言,断言json数据,工作原理,全局,环境变量,时间戳,请求前置脚本,关联,批量执行测试用例
1060 Are They Equal
W3C introduces decentralized identifier as web standard
First hello of SOC_ World experiment
MySQL soul 16 ask, how many questions can you hold on to?
VMWARE平台STS证书过期
基于USB数据采集卡(DAQ)与IO模块的热电阻温度采集「建议收藏」
聊一聊JVM的内存布局