当前位置:网站首页>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 )
边栏推荐
- 重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
- 分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
- Concept and basic knowledge of network layering
- 基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
- Unity粒子特效系列-闪星星的宝箱
- 远程代码执行渗透测试——B模块测试
- There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
- Manifest of SAP ui5 framework json
- 学 SQL 必须了解的 10 个高级概念
- MySQL stored procedure
猜你喜欢

Summary of Android interview questions of Dachang in 2022 (II) (including answers)

EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?

Huawei certified cloud computing hica

EasyCVR电子地图中设备播放器loading样式的居中对齐优化

【MySQL入门】第三话 · MySQL中常见的数据类型

Automatic operation and maintenance sharp weapon ansible Foundation

Concept and basic knowledge of network layering

OliveTin能在网页上安全运行shell命令(上)

Vscode matches and replaces the brackets

Distinguish between basic disk and dynamic disk RAID disk redundant array
随机推荐
Huawei certified cloud computing hica
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
It doesn't make sense without a distributed gateway
Guidelines for preparing for the 2022 soft exam information security engineer exam
开源与安全的“冰与火之歌”
Essai de pénétration du Code à distance - essai du module b
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
Wechat applet obtains mobile number
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
Flink analysis (I): basic concept analysis
PyTorch 提取中间层特征?
[introduction to MySQL] third, common data types in MySQL
TCP连接不止用TCP协议沟通
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
Binary search strategy
2022年大厂Android面试题汇总(一)(含答案)
How uipath determines that an object is null
[ASM] introduction and use of bytecode operation classwriter class
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
The art of Engineering (1): try to package things that do not need to be exposed