当前位置:网站首页>Getting started with pytest ----- test case rules
Getting started with pytest ----- test case rules
2022-07-06 17:49:00 【Peng Yuyan in the testing industry】
One 、pytest Test case rules
1. Module name must be test_
Beginning or _test
ending
2. The test class must be Test
Start and cannot have init
Method
3. The test method must be test
start
Two 、pytest Test case operation mode
1、 Main function mode
a) Run all :pytest.main()
b) Specify modules / Catalog :pytest.main(['-s', ' Specify the module name .py'])
【 notes : If the specified module is package Package all the files , Then pass on package The path is just 】
c) adopt nodeid
Specify the use case run :nodeid
By module name 、 Separator 、 Class name 、 Method name 、 The function name consists of . for example :
pytest.main(['-s', ' route / Specify the module name .py:: Class name :: Method name '])
2、 Command line mode
a) Run all :pytest
b) Specify modules / Catalog :pytest -s Specify the module name .py
【 notes : If the specified module is package Package all the files , Then pass on package The path is just 】
3、 Read pytest.ini
The configuration file 【** In practice, we need be used , above all **】
pytest.ini
This file is pytest Configuration file of unit test framework .
Location : It is usually placed in the project root directory , And the name cannot be changed
code : Must be ANSI, It can be used notepad++ Modify encoding format
effect : You can change pytest The default behavior ( For example, you don't want to use cases with test start , Then come here to change )
Operation rules : Whether running in main function or command line mode , Will read the configuration file .
How to write it :
New at root pytest.ini
file
【 notes : So that you can understand , It is suggested to delete the Chinese notes when using 】
If you prompt
Coding error . Can pass notepad++ Open this file , Then modify the code to ANSI( It is suggested to delete the Chinese Notes )
3、 ... and 、 Parameters, ( To list list
Mode reference )
-s
The output case debugging information includesprint
The content of-v
In addition to outputting debugging information , It also displays the class name, use case method name-vs
-v and -s Come together-n
Support multithreading or distributed operation ; example :pytest.main(['-vs', 'testcase/', '-n=2'])
or
pytest -vs ./testcase -n 2
--reruns
Run again after failure , Need to installpytest-rerunfailures
library , grammar :pytest.main(['-vs', 'testcase/', '--reruns=2'])
When case execution fails , Will repeat 2 Time .-x
As long as there is an error in one use case , Then the use case stops . grammar :pytest.main(['-vs', 'testcase/', '-x'])
--maxfail Stop after reporting an error at most . above -x If it is an error, stop , This is the maximum number of use case errors that can be accepted . grammar :--maxfail=2
-k Specify the test case according to the partial string of the test case . grammar :
pytest.main(['-vs', 'testcase/', '-k', ' Characters in the use case name '])
3、 ... and 、pytest The order in which test cases are executed
unittest: according to ASCII To determine the execution order
pytest: Default from top to bottom . If you don't want to perform from top to bottom , Can be marked :
@pytest.mark.run(order=n)
end This is the end of today's sharing , Knowledge will be shared in the future
The following is the supporting information , For doing 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you !
Last : It can be in the official account : Programmer Xiaohao ! Get a free copy of 216 Page software testing engineer interview guide document information . And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One button, three links ! Friends who like software testing , You can join our testing technology exchange group :779450660 There are various software testing resources and technical discussions )
边栏推荐
- C WinForm series button easy to use
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- 面试突击63:MySQL 中如何去重?
- 面试突击62:group by 有哪些注意事项?
- TCP连接不止用TCP协议沟通
- Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
- There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
- Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
- Single responsibility principle
- Huawei certified cloud computing hica
猜你喜欢
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
面试突击63:MySQL 中如何去重?
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
Integrated development management platform
Unity小技巧 - 绘制瞄准准心
sql语句优化,order by desc速度优化
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
【ASM】字节码操作 ClassWriter 类介绍与使用
Unity particle special effects series - treasure chest of shining stars
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
随机推荐
How to output special symbols in shell
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
Kali2021 installation and basic configuration
OpenCV中如何使用滚动条动态调整参数
Debug and run the first xv6 program
Development and practice of lightweight planning service tools
C# NanoFramework 点灯和按键 之 ESP32
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
sql语句优化,order by desc速度优化
EasyCVR授权到期页面无法登录,该如何解决?
MySQL stored procedure
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Interview shock 62: what are the precautions for group by?
Uipath browser performs actions in the new tab
Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
网络分层概念及基本知识
自动化运维利器ansible基础
[introduction to MySQL] third, common data types in MySQL
8位MCU跑RTOS有没有意义?