当前位置:网站首页>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 )
边栏推荐
- 【MySQL入门】第三话 · MySQL中常见的数据类型
- 虚拟机启动提示Probing EDD (edd=off to disable)错误
- 02 personal developed products and promotion - SMS platform
- Debug xv6
- The art of Engineering (3): do not rely on each other between functions of code robustness
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
- Shell input a string of numbers to determine whether it is a mobile phone number
- Flink parsing (IV): recovery mechanism
- Precipitated database operation class - version C (SQL Server)
- Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
猜你喜欢
TCP connection is more than communicating with TCP protocol
Integrated development management platform
Basic configuration and use of spark
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
面试突击63:MySQL 中如何去重?
Easy introduction to SQL (1): addition, deletion, modification and simple query
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
The solution that flutterweb browser cannot be rolled back after refreshing
随机推荐
02 personal developed products and promotion - SMS platform
全网最全tcpdump和Wireshark抓包实践
2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
面试突击62:group by 有哪些注意事项?
The problem of "syntax error" when uipath executes insert statement is solved
BearPi-HM_ Nano development board "flower protector" case
Reppoints: advanced order of deformable convolution
[introduction to MySQL] third, common data types in MySQL
Interview shock 62: what are the precautions for group by?
TCP connection is more than communicating with TCP protocol
Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
Flink parsing (V): state and state backend
10 advanced concepts that must be understood in learning SQL
Distinguish between basic disk and dynamic disk RAID disk redundant array
Flink analysis (I): basic concept analysis
Basic configuration and use of spark
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
How to output special symbols in shell