当前位置:网站首页>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")
边栏推荐
- SAP Spartacus express checkout design
- Bookmark collection management software suspension reading and data migration between knowledge base and browser bookmarks
- 判断数组中是否存在重复元素
- What is the relationship between realizing page watermarking and mutationobserver?
- Mysql索引
- Aiphacode is not a substitute for programmers, but a tool for developers
- Tee command usage example
- [ue5] animation redirection: how to import magic tower characters into the game
- Remember a simple Oracle offline data migration to tidb process
- 合并有序数列
猜你喜欢
随机推荐
[illusory] weapon slot: pick up weapons
虚幻材质编辑器基础——如何连接一个最基本的材质
Project practice, redis cluster technology learning (10)
Tee command usage example
Blender摄像机环绕运动、动画渲染、视频合成
MySQL -- time zone / connector / driver type
Career planning and development
Ue5 - ai Pursuit (Blueprint, Behavior tree)
The primary market project galaxy will conduct public offering on coinlist on February 17
【Lua】常见知识点汇总(包含常见面试考点)
Feature (5): how to organize information
ICLR 2022: how does AI recognize "things I haven't seen"?
Junit4运行mvn test 测试套件升级方案
Following nym, the new project Galaxy token announced by coinlist is gal
What is the relationship between realizing page watermarking and mutationobserver?
ue4材质的入门和原理笔记
MySQL transaction
Alibaba cloud SMS service
The latest progress and development trend of 2022 intelligent voice technology
Brief analysis of edgedb architecture









