当前位置:网站首页>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 reportBy 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")
边栏推荐
- 【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
- UE illusory engine programmed plant generator setup -- how to quickly generate large forests
- This monitoring system makes workers tremble: turnover intention and fishing can be monitored. After the dispute, the product page has 404
- XA Transaction SQL Statements
- Matlab generates DSP program -- official routine learning (6)
- Blender volume fog
- Summary of demand R & D process nodes and key outputs
- 【虚幻】过场动画笔记
- Basic notes of illusory AI blueprint (10000 words)
- What wires are suitable for wiring on bread board?
猜你喜欢
Matlab生成dsp程序——官方例程学习(6)
Understand the composition of building energy-saving system
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Blender ocean production
【虚幻4】UMG组件的简介与使用(更新中...)
Blender多镜头(多机位)切换
Applet development summary
Ue5 - AI pursuit (blueprint, behavior tree)
webUI自动化学习
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
随机推荐
Vscode set JSON file to format automatically after saving
渗透测试的介绍和防范
Vscode auto format
2021-09-12
Operator exercises
Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
How to judge the quality of primary market projects when the market is depressed?
Blender摄像机环绕运动、动画渲染、视频合成
allure--常用配置项
2837xd code generation module learning (3) -- IIC, ECAN, SCI, watchdog, ECAP modules
Configuration programmée du générateur de plantes du moteur illusoire UE - - Comment générer rapidement une grande forêt
Database -- acid of transaction -- introduction / explanation
阿里云ack介绍
Tee command usage example
[unreal] animation notes of the scene
Remember a simple Oracle offline data migration to tidb process
[illusory] automatic door blueprint notes
【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
Remember the use of add method once
[unreal] key to open the door blueprint notes