当前位置:网站首页>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")
边栏推荐
- 【UE5】蓝图制作简单地雷教程
- 【UE5】AI随机漫游蓝图两种实现方法(角色蓝图、行为树)
- 【虚幻】过场动画笔记
- Project practice, redis cluster technology learning (IX)
- Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
- Database -- acid of transaction -- introduction / explanation
- Blender海洋制作
- pytest框架实现前后置
- Blender摄像机环绕运动、动画渲染、视频合成
- What is the relationship between realizing page watermarking and mutationobserver?
猜你喜欢

Blender海洋制作

What wires are suitable for wiring on bread board?

The latest progress and development trend of 2022 intelligent voice technology

2021-10-02

MySQL index

Blender ocean production

Basic notes of illusory AI blueprint (10000 words)

Leetcode -- the nearest common ancestor of 236 binary tree

虚幻——动画蓝图、状态机制作人物走跑跳动作
![[illusory] automatic door blueprint notes](/img/7a/14a66e5b623c7740dc91a15a328b10.png)
[illusory] automatic door blueprint notes
随机推荐
Aiphacode is not a substitute for programmers, but a tool for developers
Feature (5): how to organize information
2837xd code generation module learning (1) -- GPIO module
Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
【Unity3D】无法正确获取RectTransform的属性值导致计算出错
This article takes you to learn in detail what is fiber to home FTTH
go语言入门
【UE5】动画重定向:如何将幻塔人物导入进游戏玩耍
Sil/pil test of matlab code generation
Commutateur Multi - lentilles Blender
Database -- acid of transaction -- introduction / explanation
Mixed development of uni app -- Taking wechat applet as an example
阿里云短信服务
Junit5 supports suite methods
SAP Spartacus express checkout design
Blender多镜头(多机位)切换
Operator exercises
【虚幻】过场动画笔记
Message mechanism -- getting to know messages and message queues for the first time
ERROR 1118 (42000): Row size too large (> 8126)