当前位置:网站首页>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 )
边栏推荐
- Display picture of DataGridView cell in C WinForm
- 酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
- Zen integration nails, bugs, needs, etc. are reminded by nails
- VR全景婚礼,帮助新人记录浪漫且美好的场景
- MySQL 8 sub database and table backup database shell script
- 偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
- sql语句优化,order by desc速度优化
- [introduction to MySQL] the first sentence · first time in the "database" Mainland
- connection reset by peer
- node の SQLite
猜你喜欢

重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...

【MySQL入门】第一话 · 初入“数据库”大陆

Interpretation of Flink source code (II): Interpretation of jobgraph source code

JMeter interface test response data garbled

Development and practice of lightweight planning service tools

BearPi-HM_ Nano development environment

Sqoop I have everything you want

Vscode matches and replaces the brackets

一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升

Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
随机推荐
Compile and build, from the bottom to the top
How to use scroll bars to dynamically adjust parameters in opencv
Awk command exercise
Establishment of graphical monitoring grafana
Growth of operation and maintenance Xiaobai - week 7
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
How uipath determines that an object is null
FlutterWeb浏览器刷新后无法回退的解决方案
05 personal R & D products and promotion - data synchronization tool
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
SQL statement optimization, order by desc speed optimization
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
自动化运维利器ansible基础
【ASM】字节码操作 ClassWriter 类介绍与使用
RepPoints:可形变卷积的进阶
VR全景婚礼,帮助新人记录浪漫且美好的场景
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
Optimization of middle alignment of loading style of device player in easycvr electronic map
Interview assault 63: how to remove duplication in MySQL?