当前位置:网站首页>Automated testing -- Introduction and use of pytest itself and third-party modules
Automated testing -- Introduction and use of pytest itself and third-party modules
2022-06-26 09:52:00 【Tanzanian auduvi Canyon expert】
pytest-html Test report
install :
:pip3 install pytest-html
send ⽤⽅ type :
1. command ⾏⽅ type
2. To configure ⽂ Pieces of ⾥
command :
--html=⽣ Report path / Report name .html
--junitxml=⽣ Report path / Report name .xml
Should be ⽤:
command ⾏
pytest --html=xx.html
# At present ⽬ record ⽣ become xx.html⽂ Pieces of
pytest --html=./report/result.html
# At present ⽬ Recording meeting ⾃ Create report⽂ Clip ,⽂ In clip ⽣ become result.html
# Be careful : There must be no spaces on either side of the equal sign
pytest-rerunfailures Failure to retry
install :pip3 install pytest-rerunfailures
send ⽤⽅ type :
command ⾏
To configure ⽂ Pieces of
command :--reruns n (n: The number of retries )
Be careful : The retry plug-in cannot be connected with setup_class⼀ Start to make ⽤,⾮ The first ⼀ One test ⽅ The law failed , There will be logical errors
↑↑↑ The above two configuration files refer to ↑↑↑:
[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 Control the execution of the test function ⾏ The order :
install : pip3 install pytest-ordering
send ⽤:
@pytest.mark.run(order=x)
x: All positive or all negative numbers , Value more ⼩, The test of embellishment ⽅ The higher the priority of the law ⾼
x: When both positive and negative numbers exist , Positive number modification test ⽅ Law priority ⾼
x: by 0 when , Highest priority ⾼
x: When it's negative , The priority is lower than the undecorated test ⽅ Law
x: A positive number is , priority ⾼ Apply to undecorated tests ⽅ Law
Skip the test method :
@pytest.mark.skipif(condtion, reason) # send ⽤ There are fewer scenes
condtion: Required
reson: Required
Combine :
1. Condition is True+ There's a reason Of board ⾏ skip
2. Condition is False+ There's a reason Do not cling to ⾏ skip
3. Only reason Also hold on to ⾏ skip
4.⽆ Conditions +⽆ reason Also hold on to ⾏ skip
5. Only the conditions newspaper error error
Of board ⾏ Expected failed operation :
@pytest.mark.xfail(conditon, reason) # send ⽤ There are fewer scenes
condtion: Required
reson: Required
Be careful : Expected failure ⽅ The Dharma Council acquiesces in ⾏⼀ Secondary test ⽅ Law
Combine :
1. Condition is true + There's a reason Of board ⾏ Expected failure
2. The condition is false + There's a reason Do not cling to ⾏ Expected failure
3.⽆ Conditions + There's a reason Of board ⾏ Expected failure
4.⽆ Conditions + ⽆ reason Of board ⾏ Expected failure
5. Conditional + ⽆ reason newspaper error abnormal
Expected failure ⾏ result :
1. test ⽅ The law itself breaks ⾔ adopt , result xpassed
2. test ⽅ The law itself breaks ⾔ Failure , result xfailed

parametrize A parameterized :
# Single parameter
@pytest.mark.parametrize(" Parameters ", [ Parameter values 1, Parameter values 2, Parameter values 3])
result :
⽅ FA Huiyun ⾏ list ⻓ degree
Code
import pytest
class Test_001:
# Traverse the parameter value list ,⽅ Law movement ⾏ frequency = list ⻓ degree
@pytest.mark.parametrize("data", [1, 2, 3, 4])
def test_001(self, data): # paramtrize Parameter name = test ⽅ Method parameter name , The name must be ⼀ Cause
""" Judge the value in the list It's not equal to 2"""
print("\ndata:", data)
assert data != 2
# Multiple parameters
@pytest.mark.parametrize(" Parameters 1, Parameters 2", [( Parameters 1 value , Parameters 2 value ),( Parameters 1 value , Parameters 2 value )....])
Code :
import pytest
class Test_002:
# Multiple parameters in ⼀ In strings
# test ⽅ The position of method parameters can be changed
# parametrize Middle parameter name Must be equal to test ⽅ Method parameter name
@pytest.mark.parametrize("a,b,c", [(1, 2, 3), (3, 4, 5), (5, 6, 11)])
def test_002(self, a, b, c):
""" The sum of two numbers is calculated a+b == c"""
print("\na:", a)
print("\nb:", b)
print("\nc:", c)
assert a + b == c
边栏推荐
- 2021-11-29 quintic polynomial of trajectory planning
- 节流,防抖,new函数,柯里化
- 2021-11-12 vrep视觉传感器配置
- 进入页面输入框自动获取焦点
- 自动化测试——pytest框架介绍及示例
- 做测试需要知道的内容——url、弱网、接口、自动化、
- online trajectory generation
- LeetCode 498. Diagonal traversal
- Deep learning (tentsorflow2. version) three good student performance problems (1)
- 【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort
猜你喜欢

Redis notes (12) - single thread architecture (non blocking IO, multiplexing) and multiple asynchronous threads

install opencv-contrib-dev to use aruco code

Flutter's brain map notes are easy to find and search!

druid数据源实现后台监控

Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)

Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)

Badge series 4: use of circle Ci

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

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

2021-11-29 轨迹规划五次多项式
随机推荐
2021-11-12 vrep vision sensor configuration
Logical English structure [key points]
Basic grammar of C language -- pointer (character, one-dimensional array) learning
LeetCode 958. Completeness checking of binary tree
SQL function
【轨迹规划】Ruckig库的测试
Vscode common programming fonts
install opencv-contrib-dev to use aruco code
SQL query duplicate record
Redis notes (12) - single thread architecture (non blocking IO, multiplexing) and multiple asynchronous threads
2021-11-22 运动规划杂记
异常记录-23
Daily-used English phrases
DAY 3 数组,前置后置,字符空间,关键词和地址指针
#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service
Js--- get the data with the same key value in the object array to get a new array
LeetCode 958. 二叉树的完全性校验
自动化测试——pytest框架介绍及示例
mysql 数据库字段查询区分大小写设置
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程