当前位置:网站首页>Pytest learning ----- pytest operation mode and pre post packaging of interface automation testing
Pytest learning ----- pytest operation mode and pre post packaging of interface automation testing
2022-07-06 17:49:00 【Peng Yuyan in the testing industry】
One 、Pytest Advantage cognition :
1. It can combine all automated testing tools
2. Skip the failure case and rerun the failure
3. combination allure Production aesthetics report
4. and Jenkins Continuous integration
5. Many powerful plug-ins
pytest-html: production html Test report
pytest-xdist: Multithreading
pytest-ordering: Change the order of use case execution
pytest-rerunfailures: Failed case re crawl
allure-pytest: Aesthetic test report
In general projects , Will use requerments.text Document save plug-in name , Carry out batch one-time installation
pip install -r requerments.txt
Two 、 Operation mode :
1. Operation mode of main function :main Method run
2. Command operation mode pytest -vs
-v: More details
-s: Debugging information
-n= Handle : Multithreading
--reruns= Numbers : Failed use case rerun
--reruns= Numbers : Failed use case rerun
--html=./report.html: Generate html The report
Use cases run in groups
1. Group use cases :
2. Use cases are annotated :
#@pytest.mark. Group name as follows :
@pytest.mark.smoke

[pytest]
## Run the command , for example : -vs -m "smoke" Group execution names are fixed
addopts = -vs
# Test case file directory
testpaths = ./testcases
python_files = test_*.py
python_classes = Test*
python_functions = test_*
## grouping
markers =
smoke:maoyan
case:gongneng
3、 ... and 、 Front and back , fixture
1. Simple distinction : Direct call method , But when there are too many interfaces , More trouble
def setup(self):
print(" Before each use case is executed , Do it all once ")
def teardown(self):
print(" After each use case is executed , Do it all once ")
2. Realize partial pre : If you only want one use case to precede , For example, you need to connect to the database when logging in .
You need to use a device :

Parameter Introduction :
@pytest.fixture(scope=" Scope ",params=" Data driven ",autouse=" Whether to execute automatically ",ids=" Custom parameters ",name=" rename ")
Scope : Can function 、 class 、 modular 、 package 、session
Usage method :
1. The device needs to be labeled on the pre-set function
2. Call the device between other methods and functions
as follows : Some pre wakeups are performed in a file
import time
import pytest
import requests
# Implement device label pre , Annotate ,yieid Wake up and return
@pytest.fixture(scope="function")
def conn_getbase():
print(" Successfully connected to database ")
yield
print(" Closing database succeeded ")
class TestSendRequsets:
# When there are too many interfaces , It is troublesome and redundant
# def setup(self):
# print(" Before each use case is executed ")
#
# def teardown(self):
# print(" After each use case is executed ")
def test_getImgCode(self):
# Interface url
t = time.time()
timess = str(int(round(t * 1000)))
times = str(int(t))
url = "http://124.71.230.185:9002/jeecg-boot/sys/randomImage/" + "" + timess
# Parameters
data = {
"_t": times,
}
# # get request
rep = requests.request('get', url, params=data)
print(rep.text)
# Tagged as smoke Group use cases
@pytest.mark.smoke
def test_Login(self,conn_getbase):
# post request
url = "http://124.71.230.185:9002/jeecg-boot/sys/login"
# Parameters
data = {
"captcha": "[email protected]#2021",
"checkKey": 1637811815838,
"password": "123456",
"remember_me": 1,
"username": "admin"
}
rep = requests.request('post', url, json=data)
statues = rep.json()["success"]
message = rep.json()["message"]
if statues:
print("")
else:
# raise Exception(message)
print(message)
if __name__ == '__main__':
pytest.main();
3. Encapsulate flexible calls
In general :@pytest.fixture() Hui He conftest.py Use files together
conftest.py The name is fixed , Function as follows :
1. There are many uses py Share pre configuration between files .
2. When the method inside is called , No need to import , Can be called between
3. You can have more conftest.py file , There can also be different levels
conftest.py For details of the document, please see the next chapter
Realization :
1. Create between directories conftest.py file
2. Paste the above code into conftest.py In file
# Pre function
import pytest
@pytest.fixture(scope="function")
def conn_getbase():
print(" Successfully connected to database ")
yield
print(" Closing database succeeded ")
The following is the supporting information , For doing 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you !
Last : It can be in the official account : Programmer Xiaohao ! Get a free copy of 216 Page software testing engineer interview guide document information . And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One button, three links ! Friends who like software testing , You can join our testing technology exchange group :779450660 There are various software testing resources and technical discussions )
边栏推荐
- EasyCVR电子地图中设备播放器loading样式的居中对齐优化
- Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
- MySQL error reporting solution
- Unity小技巧 - 绘制瞄准准心
- Summary of Android interview questions of Dachang in 2022 (I) (including answers)
- Display picture of DataGridView cell in C WinForm
- 传统家装有落差,VR全景家装让你体验新房落成效果
- connection reset by peer
- [translation] principle analysis of X Window Manager (I)
- Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
猜你喜欢

【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符

There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house

Alibaba brand data bank: introduction to the most complete data bank

It doesn't make sense without a distributed gateway

【ASM】字节码操作 ClassWriter 类介绍与使用

EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?

SQL statement optimization, order by desc speed optimization

The NTFS format converter (convert.exe) is missing from the current system

中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障

SAP UI5 框架的 manifest.json
随机推荐
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
Openharmony developer documentation open source project
Binary search strategy
Awk command exercise
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
远程代码执行渗透测试——B模块测试
The art of Engineering (1): try to package things that do not need to be exposed
SQL statement optimization, order by desc speed optimization
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
Vscode matches and replaces the brackets
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Unity小技巧 - 绘制瞄准准心
Vscode replaces commas, or specific characters with newlines
Flink parsing (V): state and state backend
RepPoints:可形变卷积的进阶
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
OpenCV中如何使用滚动条动态调整参数
当前系统缺少NTFS格式转换器(convert.exe)
微信小程序获取手机号
C# NanoFramework 点灯和按键 之 ESP32