当前位置:网站首页>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")
边栏推荐
- Commutateur Multi - lentilles Blender
- MySQL transaction
- Project practice, redis cluster technology learning (VII)
- XA Transaction SQL Statements
- 【UE5】蓝图制作简单地雷教程
- Junit4运行mvn test 测试套件升级方案
- webUI自动化学习
- Message mechanism -- getting to know messages and message queues for the first time
- How to achieve the top progress bar effect in background management projects
- Blender多镜头(多机位)切换
猜你喜欢

Blender体积雾

Introduction and Principle notes of UE4 material

pytest框架实现前后置

Commutateur Multi - lentilles Blender

How to judge the quality of primary market projects when the market is depressed?
![[ue5] animation redirection: how to import magic tower characters into the game](/img/a0/084381493cbc3992b61ef1b8ffce36.png)
[ue5] animation redirection: how to import magic tower characters into the game

Skywalking theory and Practice

High level application of SQL statements in MySQL database (II)

Mock Server基本使用方法

SAP Spartacus express checkout design
随机推荐
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
Delivery mode design of Spartacus UI of SAP e-commerce cloud
How does {} prevent SQL injection? What is its underlying principle?
Skywalking理论与实践
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
【避坑指南】Unity3D项目接入腾讯Bugly工具时遇到的坑
Post disaster reconstruction -- Floyd thought
Brief analysis of edgedb architecture
虛幻AI藍圖基礎筆記(萬字整理)
Mysql索引
Vscode auto format
allure--常用配置项
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
Junit5 支持suite的方法
[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
Zlib download and use
Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
UE illusory engine programmed plant generator setup -- how to quickly generate large forests
Blender stone carving
Blender camera surround motion, animation rendering, video synthesis