当前位置:网站首页>Pytest learning --base
Pytest learning --base
2022-07-02 10:22:00 【Lost ~ know to return】
pytest Unit test framework
Unit testing refers to the process of software development , The smallest unit for software ( function 、 Method ) Carry out correct inspection and test
Unit test framework :
java:junit and testing
python:unnitest and pytest
What does the unit test framework mainly do
- Tests found : Find our test cases from multiple files
- The test execution : Execute in a certain order and rules , And generate results
- Test judgment : Judge the difference between the expected results and the world results through assertions
- Test report : Statistical test progress , Time consuming , Passing rate , Generate test reports
What is the relationship between unit test framework and automation test framework - What is automated testing framework : To complete the complete code framework of the whole system , Encapsulate the basic modules of Automation , Management module
- effect
- Improve test efficiency , Lower maintenance costs
- Reduce human intervention , Improve the accuracy of the test , Increase code reuse
- The core idea is to enable people who don't understand the code to realize automated testing through this framework
- pytest The relationship between unit testing and automated testing framework
- Unit test framework :
- pom Design patterns
- Data driven
- Keyword Driven
- Encapsulation of global configuration files
- Log monitoring
- selienium,requests
- Assertion
- Report mail
pytest brief introduction
1、pytest It's a very mature python Unit test framework , Than unnitest Simple
2、pytest You can talk to selinum,requests,appinum In combination with implementation web automation , Interface automation ,APP automation
3、pytest You can skip test cases and returns Retry of failed cases
4、pytest You can talk to allture Generate very beautiful test reports
5、pytest You can talk to jenkins Continuous integration
6、pytest There are many very powerful plug-ins , And these plug-ins can realize many operations
- pytest
- pytest-html( Generate html Automated test report in )
- pytest-xdist Test cases are executed step by step , many cpu distribution
- pytest-ordering Used to change the execution order of use cases
- pytest-returning Run again after the use case fails
- allure-pytest Used to generate beautiful test reports
- Put it in requirement.txt Through the file pip install -r requirement.txt
Use pytest, Default test case rules and basic application
- 1、 Module name must be test_ perhaps _test ending
- 2、 The test class must be Test start , Can not have __init__ Method
- 3、 The test method must be test start
pytest How test cases run
Run in main function mode
- Run all :pytest.main()
Specify modules :pytest.main([‘-vs’,‘test_login.py’])
Specify the directory to run :pytest.main([‘-vs’,‘./interface/test_01_inter.py’])
adopt nodeid Specify the use case run :node By module name , Separator , Class name , Method name , The function name consists ofRun in command line mode
- Run all pytest
Specify the module to run pytest -vs test_login.py
Specify the directory to run :pytest -vs ./interface/test_01_inter.py
Parameters, :
-s: The output debugging information includes print Printed information
-v: Show more details
-vs: These two parameters are used together
-n: Support multithreading or distributed running of test cases
pytest -vs ./testcase/test_login.py -n 2
-x: It means that as long as there is an error in one use case , Then the test stops
-k: Specify the test case according to the partial string of the test case
Such as :pytest -vs ./testcase -k “ao”
–html Generate html The report
By reading the pytest.ini Profile run
-pytest.ini This document he is pytest The core configuration file of unit test mining construction
- Location : It is usually placed in the root directory of the project
- code :ASCII code , have access to nopad++ Modify encoding format
- effect : change pytest The default behavior
- Operation rules : Whether it's the running mode of the main function , Run in command line mode , Go back and read the configuration file
[pytest]
addopts=-vs # The command line arguments are
testpaths=./testcase # Path of test case
python_files = test_*.py # Rules for module names
python_classes = Test* # Rules for class names
python_functions = test # Rules for method names
marks =
smoke: Smoke use case
usermanage: User management module
6、 ... and 、pytest The order in which test cases are executed :
The default execution mode is from top to bottom
Mark to execute
Group execution ( smoking , Interface ,web)
smoke: Cat's eye use case , Distributed in each module
pytest -m “smoke”
pytest -m "smoke or usermanage"t
Skip test cases
(1) Jump unconditionally
pytest.mark.skip(reason="xxxx")
class TestCar:
age = 20
@pytest.mark.skip(reason="xxxxxx")
def test_01_car(self):
print("this is old car")
(2) Conditional skip
class TestCar:
age = 20
@pytest.mark.skipif(age>=18,reason="xxxxxxx")
def test_01_car(self):
print("this is old car")
pytest.mark.skipif(age>=18,reason="xxxxxxx")
边栏推荐
- Project practice, redis cluster technology learning (12)
- Matlab生成dsp程序——官方例程学习(6)
- [200 Shengxin literatures] 96 joint biomarkers of immune checkpoint inhibitor response in advanced solid tumors
- Post disaster reconstruction -- Floyd thought
- Blender摄像机环绕运动、动画渲染、视频合成
- [ue5] blueprint making simple mine tutorial
- pytest--之测试报告allure配置
- allure--常用配置项
- 2021-10-04
- pytest框架实现前后置
猜你喜欢

How to judge the quality of primary market projects when the market is depressed?

UE5——AI追逐(藍圖、行為樹)

阿里云ack介绍

Blender多镜头(多机位)切换

判断数组中是否存在重复元素

Unreal material editor foundation - how to connect a basic material

【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh

Introduction et prévention des essais de pénétration

pytest--之测试报告allure配置

Junit5 supports suite methods
随机推荐
Matlab generates DSP program -- official routine learning (6)
Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
Feature (5): how to organize information
Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
2837xd code generation module learning (1) -- GPIO module
网络通信学习
ESLint 报错
[leetcode] sword finger offer 53 - I. find the number I in the sorted array
About the college entrance examination
Illusion -- Animation blueprint, state machine production, character walking, running and jumping action
A model can do two things: image annotation and image reading Q & A. VQA accuracy is close to human level | demo can be played
AutoCAD - layer Linetype
Project practice, redis cluster technology learning (VII)
Pycaret | a few lines of code to solve machine learning modeling
High level application of SQL statements in MySQL database (II)
Blender摄像机环绕运动、动画渲染、视频合成
Nonlinear optimization: establishment of slam model
Vscode auto format
Postman--使用
滲透測試的介紹和防範