当前位置:网站首页>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
边栏推荐
- Badge collection 6:api\_ Use of level
- jz2440---使用uboot烧录程序
- Deep learning (tentsorflow2. version) three good student performance problems (1)
- Meaning of go runtime
- The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
- Flink入门——单词统计
- I am in Zhongshan. Where can I open an account? Is online account opening safe?
- 工企专利匹配数据(数十万数据量)1998-2014年
- jz2440---使用uboot燒錄程序
- The 100000 line transaction lock has opened your eyes.
猜你喜欢

c语言语法基础之——指针( 多维数组、函数、总结 ) 学习

我的创作纪念日

国际化配置

2021-11-22 运动规划杂记

The basis of C language grammar -- pointer (multidimensional array, function, summary) learning

逻辑英语结构【重点】

What you need to know to test -- URL, weak network, interface, automation

Badge series 4: use of circle Ci

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

Custom interceptor
随机推荐
Introduction to QPM
Explained: A Style-Based Generator Architecture for GANs (StyleGAN)
Does the go compiled executable have dynamic library links?
c语言语法基础之——函数 小程序 求阶乘
Thinking before QPM preparation optimization
Go learning notes (83) - code specification and common development skills
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)
A concise tutorial for getting started with go generics
online trajectory generation
QPM suspended window setting information
Teach you to use shell script to check whether the server program is running
From TF 1 X to TF 2.6 (update if you encounter it)
Throttling, anti chattering, new function, coriolism
教你用shell脚本检测服务器程序是否在运行
DAY 3 数组,前置后置,字符空间,关键词和地址指针
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
How to correctly open the USB debugging and complete log functions of Huawei mobile phones?
Redis 新手入门
SQL 函数