当前位置:网站首页>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
边栏推荐
- [set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
- [untitled] 8 simplified address book
- [5g NR] UE registration process
- “我为开源打榜狂”第一周榜单公布,160位开发者上榜
- (翻译)异步编程:Async/Await在ASP.NET中的介绍
- 爬虫代码基础教学
- golang操作redis:写入、读取hash类型数据
- Push box games C #
- Various usages of MySQL backup database to create table select and how many days are left
- Understand software testing
猜你喜欢

【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案

HMS core helps baby bus show high-quality children's digital content to global developers

golang操作redis:写入、读取hash类型数据
![[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle](/img/f8/0e3fbfd13bf06291a73200552ff17a.png)
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle

Scripy learning

ruoyi接口权限校验

如何迁移或复制VMware虚拟机系统

DBNet:具有可微分二值化的实时场景文本检测

IE browser flash back, automatically open edge browser

2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
随机推荐
Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
SQL implementation merges multiple rows of records into one row
10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
Summary of the design and implementation of the weapon system similar to the paladin of vitality
ruoyi接口权限校验
远端rostopic的本地rviz调用及显示
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
scroll-view指定滚动元素的起始位置
利用C#实现Pdf转图片
[LeetCode]404. 左叶子之和
修改MySQL密码
爬虫代码基础教学
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
Know flex box
【无标题】5 自用历程
保险公司怎么查高血压?
Unittest attempt
Heap sort and priority queue
Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
Judge whether the date time exceeds 31 days