当前位置:网站首页>Getting started with pytest
Getting started with pytest
2022-07-03 06:44:00 【Xiaojing, who likes dumplings】
pytest Official website
Reference resources :link
pytest install
pip install pytest
pytest Case rules
pytest --help You can see pytest Help document for
C:\Users\Administrator>pytest --help
usage: pytest [options] [file_or_dir] [file_or_dir] […]
function pytest You can specify directories and files , If you don't specify ,pytest Will search for profiles testpaths The defined directory or the current directory and its subdirectories are marked with test_ Begin with or with _test At the end of the py file
[file_or_dir] You can specify a file or directory
We put pytest The process of searching test files and test cases is called test search (test discovery), As long as you follow pytest Naming rules ,pytest Can automatically search all test cases to be executed , The following rules :
(1) The test file should be named test_.py perhaps test.py
(2) Test functions 、 Test class methods should be named test
(3) The test class should be named Test, And there can be no __init__ Method
pytest Command line arguments
-v --verbose increase verbosity Show details
–collect-only Show which examples will be run , Only show cases without running
-k Use an expression to specify the case to run , have access to or and etc.
such as : The names of the two test cases test_asdict() and test_defaults(), Use –k When this parameter
pytest -k “asdict or defaults”
-m Specify tags to run
Test cases can use pytest.mark.mock perhaps pytest.mark,regression Such decorators are used to mark grouped test cases , Using parameter -m You can select tags to run
Such as , You need to run the test cases marked as smoke phase pytest -m “mock”
Expressions can use or and not etc.
-x Under normal circumstances ,pytest After encountering failed or abnormal use cases , We will continue to execute the next use case , If you want to let pytest Stop executing the failed use case , Use -x This parameter
–maxfail=num -x The feature of the option is , Once a test fails , It will stop globally , Suppose you allow pytest Fail several times and then stop , You can use –maxfail
-s Allow the terminal to output some results during the test run , Include any output information that meets the standard , such as print Information about
–capture=fd Written to a temporary file
–capture=sys Output memory
–lf When one or more tests fail , Locate the last failed test case and rerun , Only execute the last failed use case and re execute
E:\JenkinsLearn\My-pytest>pytest --lf
======================================================================= test session starts =======================================================================
platform win32 -- Python 3.8.5, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: E:\JenkinsLearn\My-pytest
plugins: cov-3.0.0
collected 1 item
run-last-failure: rerun previous 1 failure
test\test_my_add.py F
–ff --failed-first And –lf The same effect , however -ff Will run the remaining test cases
E:\JenkinsLearn\My-pytest>pytest --ff
======================================================================= test session starts =======================================================================
platform win32 -- Python 3.8.5, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: E:\JenkinsLearn\My-pytest
plugins: cov-3.0.0
collected 4 items
run-last-failure: rerun previous 1 failure first
test\test_my_add.py F...
-l --showlocals Use -l Options , The failed test case is traced by the stack , So the local variables and their only display
–tb=style --tb=styl Option determines how to display the output information when capturing failure , After a test case fails ,pytest Will list failure information , Including the line where the failure occurs , What is the failure , How to fail , This process is called “ Information backtracking ”
–tb=no Block all backtracking information
–tb=line Show the wrong location
–tb=short The backtracking information displayed is more detailed than the previous two modes
–tb=long Output the most auspicious backtracking information
–version Can display the current pytest Version and installation directory
边栏推荐
- 方差迭代公式推导
- 简易密码锁
- Selenium - by changing the window size, the width, height and length of different models will be different
- Time format record
- The pressure of large institutions in the bear market has doubled. Will the giant whales such as gray scale, tether and micro strategy become 'giant thunder'?
- 认识弹性盒子flex
- scroll-view指定滚动元素的起始位置
- JMeter linked database
- Printer related problem record
- 【LeetCode】Day93-两个数组的交集 II
猜你喜欢
Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
Personally design a highly concurrent seckill system
Time format record
IE browser flash back, automatically open edge browser
Une exploration intéressante de l'interaction souris - pointeur
熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
Operation principle of lua on C: Foundation
Journal quotidien des questions (11)
Scroll view specifies the starting position of the scrolling element
随机推荐
SSH link remote server and local display of remote graphical interface
[LeetCode]404. 左叶子之和
100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
Support vector machine for machine learning
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
opencv鼠标键盘事件
认识弹性盒子flex
The most classic 100 sentences in the world famous works
有意思的鼠標指針交互探究
Judge whether the date time exceeds 31 days
2022-06-23 VGMP-OSPF-域間安全策略-NAT策略(更新中)
golang操作redis:写入、读取kv数据
Summary of remote connection of MySQL
Luogu problem list: [mathematics 1] basic mathematics problems
C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
Asynchronous programming: async/await in asp Net
How matlab modifies default settings
Scroll view specifies the starting position of the scrolling element
Time format record
(翻译)异步编程:Async/Await在ASP.NET中的介绍