当前位置:网站首页>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 )
边栏推荐
- PyTorch 提取中间层特征?
- Mysqlimport imports data files into the database
- Run xv6 system
- TCP connection is more than communicating with TCP protocol
- sql语句优化,order by desc速度优化
- EasyCVR电子地图中设备播放器loading样式的居中对齐优化
- 2022年大厂Android面试题汇总(二)(含答案)
- Binary search strategy
- 基于STM32+华为云IOT设计的智能路灯
- Essai de pénétration du Code à distance - essai du module b
猜你喜欢
How to use scroll bars to dynamically adjust parameters in opencv
全网最全tcpdump和Wireshark抓包实践
基于STM32+华为云IOT设计的智能路灯
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
FlutterWeb浏览器刷新后无法回退的解决方案
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
Establishment of graphical monitoring grafana
2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
About selenium starting Chrome browser flash back
随机推荐
Interpretation of Flink source code (II): Interpretation of jobgraph source code
RepPoints:可形变卷积的进阶
Vscode replaces commas, or specific characters with newlines
Automatic operation and maintenance sharp weapon ansible Playbook
开源与安全的“冰与火之歌”
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
MySQL stored procedure
Flink analysis (I): basic concept analysis
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
自动化运维利器ansible基础
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
Solrcloud related commands
Huawei certified cloud computing hica
About selenium starting Chrome browser flash back
【ASM】字节码操作 ClassWriter 类介绍与使用
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
Wechat applet obtains mobile number
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
Integrated development management platform