当前位置:网站首页>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
边栏推荐
- thinkphp6.0的第三方扩展包,支持上传阿里云,七牛云
- Specific implementation comparison between different programming languages
- Daily-used English phrases
- LeetCode 接雨水系列 42.(一维) 407.(二维)
- From TF 1 X to TF 2.6 (update if you encounter it)
- The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
- Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)
- Getting started with Flink - word statistics
- 做测试需要知道的内容——url、弱网、接口、自动化、
- The 100000 line transaction lock has opened your eyes.
猜你喜欢
How to correctly open the USB debugging and complete log functions of Huawei mobile phones?

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

定制拦截器

logback

Badge series 4: use of circle Ci

jz2440---使用uboot燒錄程序

A Style-Based Generator Architecture for Generative Adversarial Networks

国际化配置

install opencv-contrib-dev to use aruco code

logback
随机推荐
Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial
Flink入门——单词统计
install opencv-contrib-dev to use aruco code
Teach you to use shell script to check whether the server program is running
pcl install
online trajectory generation
Throttling, anti chattering, new function, coriolism
Flutter's brain map notes are easy to find and search!
cento7.7安装ELK简单记录
From TF 1 X to TF 2.6 (update if you encounter it)
thinkphp6.0的第三方扩展包,支持上传阿里云,七牛云
How does flutter transfer parameters to the next page when switching pages?
libgstreamer-1.0. so. 0: cannot open shared object file: No such file or directory
Upgrade idea to 2021.2 shortcut keys
QPM performance monitoring components - General
The 100000 line transaction lock has opened your eyes.
Specific implementation comparison between different programming languages
LeetCode 接雨水系列 42.(一维) 407.(二维)
Opencv depthframe - > pointcloud causes segmentation fault!