当前位置:网站首页>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 )
边栏推荐
- 78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
- 05 personal R & D products and promotion - data synchronization tool
- Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
- Spark accumulator and broadcast variables and beginners of sparksql
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Alibaba brand data bank: introduction to the most complete data bank
- Reppoints: advanced order of deformable convolution
- Pytorch extract middle layer features?
- SAP UI5 框架的 manifest.json
- [elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
猜你喜欢
Smart street lamp based on stm32+ Huawei cloud IOT design
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
Flink parsing (VII): time window
一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
The NTFS format converter (convert.exe) is missing from the current system
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
SAP UI5 框架的 manifest.json
pip install pyodbc : ERROR: Command errored out with exit status 1
Unity particle special effects series - treasure chest of shining stars
node の SQLite
随机推荐
pip install pyodbc : ERROR: Command errored out with exit status 1
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
How to use scroll bars to dynamically adjust parameters in opencv
微信小程序获取手机号
How uipath determines that an object is null
Single responsibility principle
In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
Interview shock 62: what are the precautions for group by?
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
Shell input a string of numbers to determine whether it is a mobile phone number
MySQL error reporting solution
Unity粒子特效系列-闪星星的宝箱
Flink parsing (IV): recovery mechanism
[introduction to MySQL] third, common data types in MySQL
node の SQLite
Solrcloud related commands
学 SQL 必须了解的 10 个高级概念
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
Spark calculation operator and some small details in liunx