当前位置:网站首页>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 )
-sThe output case debugging information includesprintThe content of-vIn addition to outputting debugging information , It also displays the class name, use case method name-vs-v and -s Come together-nSupport multithreading or distributed operation ; example :pytest.main(['-vs', 'testcase/', '-n=2'])or
pytest -vs ./testcase -n 2
--rerunsRun again after failure , Need to installpytest-rerunfailureslibrary , grammar :pytest.main(['-vs', 'testcase/', '--reruns=2'])When case execution fails , Will repeat 2 Time .-xAs 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 )
边栏推荐
- Integrated development management platform
- [rapid environment construction] openharmony 10 minute tutorial (cub pie)
- After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
- Spark accumulator and broadcast variables and beginners of sparksql
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- Nodejs 开发者路线图 2022 零基础学习指南
- How to use scroll bars to dynamically adjust parameters in opencv
- Uipath browser performs actions in the new tab
- Flink parsing (IV): recovery mechanism
- The art of Engineering
猜你喜欢

The problem of "syntax error" when uipath executes insert statement is solved

Uipath browser performs actions in the new tab

基本磁盘与动态磁盘 RAID磁盘冗余阵列区分

OpenCV中如何使用滚动条动态调整参数

网络分层概念及基本知识

RepPoints:可形变卷积的进阶

About selenium starting Chrome browser flash back

02 personal developed products and promotion - SMS platform

Zen integration nails, bugs, needs, etc. are reminded by nails

The most complete tcpdump and Wireshark packet capturing practice in the whole network
随机推荐
[ASM] introduction and use of bytecode operation classwriter class
Sqoop I have everything you want
Automatic operation and maintenance sharp weapon ansible Playbook
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
MySQL 8 sub database and table backup database shell script
Solid principle
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
02 personal developed products and promotion - SMS platform
Grafana 9 正式发布,更易用,更酷炫了!
Wordcloud colormap color set and custom colors
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
kivy教程之在 Kivy 中支持中文以构建跨平台应用程序(教程含源码)
网络分层概念及基本知识
Guidelines for preparing for the 2022 soft exam information security engineer exam
It doesn't make sense without a distributed gateway
node の SQLite
Manifest of SAP ui5 framework json
Flink parsing (V): state and state backend
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system