当前位置:网站首页>自动化测试——pytest本身及第三方模块介绍及使用
自动化测试——pytest本身及第三方模块介绍及使用
2022-06-26 09:34:00 【坦桑尼亚奥杜威峡谷能人】
pytest-html 测试报告
安装:
:pip3 install pytest-html
使⽤⽅式:
1.命令⾏⽅式
2.配置⽂件⾥
命令:
--html=⽣成报告路径/报告名字.html
--junitxml=⽣成报告路径/报告名字.xml
应⽤:
命令⾏
pytest --html=xx.html
# 在当前⽬录⽣成xx.html⽂件
pytest --html=./report/result.html
# 当前⽬录会⾃动创建report⽂件夹,⽂件夹内⽣成result.html
# 注意:等号两侧不能出现空格
pytest-rerunfailures 失败重试
安装:pip3 install pytest-rerunfailures
使⽤⽅式:
命令⾏
配置⽂件
命令:--reruns n (n:重试的次数 )
注意:重试插件不能和setup_class⼀起使⽤,⾮第⼀个测试⽅法失败,会出现逻辑错误
↑↑↑ 以上两种配置文件参考 ↑↑↑:
[pytest] # command line
addopts = -s --html=./report/res.html --reruns 2 # search dir
testpaths = ./scripts
# search file
python_files = test_rerun_pro.py
# search class
python_classes = Test* # search functions
python_functions = test*
pytest-ordering 控制测试函数执⾏顺序:
安装: pip3 install pytest-ordering
使⽤:
@pytest.mark.run(order=x)
x:全为正数或全为负数,值越⼩,修饰的测试⽅法优先级越⾼
x:正数和负数同时存在时,正数修饰的测试⽅法优先级⾼
x:为0时,优先级最⾼
x:为负数时,优先级低于未被修饰的测试⽅法
x:为正数是,优先级⾼于未被修饰的测试⽅法
跳过测试方法:
@pytest.mark.skipif(condtion, reason) # 使⽤场景较少
condtion:必填
reson:必填
组合:
1.条件为True+有原因 执⾏跳过
2.条件为False+有原因 不执⾏跳过
3.只有原因 也执⾏跳过
4.⽆条件+⽆原因 也执⾏跳过
5.只有条件 报error错误
执⾏预期失败操作:
@pytest.mark.xfail(conditon, reason) # 使⽤场景较少
condtion:必填
reson:必填
注意:预期失败⽅法会默认执⾏⼀次测试⽅法
组合:
1.条件为真+有原因 执⾏预期失败
2.条件为假+有原因 不执⾏预期失败
3.⽆条件 + 有原因 执⾏预期失败
4.⽆条件 + ⽆原因 执⾏预期失败
5.有条件 + ⽆原因 报error异常
预期失败执⾏结果:
1.测试⽅法本身断⾔通过,结果 xpassed
2.测试⽅法本身断⾔失败, 结果 xfailed

parametrize参数化:
# 单个参数
@pytest.mark.parametrize("参数", [参数值1,参数值2,参数值3])
结果:
⽅法会运⾏列表⻓度
代码
import pytest
class Test_001:
# 遍历参数值列表,⽅法运⾏次数 = 列表⻓度
@pytest.mark.parametrize("data", [1, 2, 3, 4])
def test_001(self, data): # paramtrize参数名=测试⽅法参数名,名称必须⼀致
"""判断列表中值 不等于 2"""
print("\ndata:", data)
assert data != 2
# 多个参数
@pytest.mark.parametrize("参数1, 参数2", [(参数1值,参数2值),(参数1值,参数2值)....])
代码:
import pytest
class Test_002:
# 多个参数在⼀个字符串中
# 测试⽅法参数位置可以调换
# parametrize中参数名 必须等于 测试⽅法参数名
@pytest.mark.parametrize("a,b,c", [(1, 2, 3), (3, 4, 5), (5, 6, 11)])
def test_002(self, a, b, c):
"""两个数相加的和计算 a+b == c"""
print("\na:", a)
print("\nb:", b)
print("\nc:", c)
assert a + b == c
边栏推荐
- LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
- Use recursion or a while loop to get the name of the parent / child hierarchy
- install realsense2: The following packages have unmet dependencies: libgtk-3-dev
- 点击遮罩层关闭弹窗
- SQL高级教程
- 十万行事务锁,开了眼界了。
- 【CVPR 2021】Unsupervised Multi-Source Domain Adaptation for Person Re-Identification (UMSDA)
- Mysql database field query case sensitive setting
- install opencv-contrib-dev to use aruco code
- 【CVPR 2021】Intra-Inter Camera Similarity for Unsupervised Person Re-Identification (IICS++)
猜你喜欢

The 100000 line transaction lock has opened your eyes.

深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)

install opencv-contrib-dev to use aruco code

Cancellation and unbinding of qiniu cloud account

How to create an IE tab in edge browser

Shared by Merrill Lynch data technology expert team, smoking detection related practice based on Jetson nano

2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial

Catalogue gradué de revues scientifiques et technologiques de haute qualité dans le domaine de l'informatique

2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程

Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
随机推荐
Redis novice introduction
Summary of common commands of vim
How to solve the problem that NVIDIA model cannot be viewed by inputting NVIDIA SMI and quickly view NVIDIA model information of computer graphics card
MapReduce&Yarn理论
【CVPR 2019】Semantic Image Synthesis with Spatially-Adaptive Normalization(SPADE)
Logical English structure [key points]
Badge series 7: use of codacy
Origin of QPM
Badge series 5: use of codecov
The first problem troubleshooting process of re disk
力扣------从数组中移除最大值和最小值
PHP does not allow images to be uploaded together with data (no longer uploading images before uploading data)
【CVPR 2021】 Lifelong Person Re-Identification via Adaptive Knowledge Accumulation
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
[Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network
logback
Enter the page input box to automatically obtain the focus
爬虫相关文章收藏:pyppeteer 、Burpsuite
十万行事务锁,开了眼界了。
【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort