怎么新建pytest的ini文件_pytest.ini配置

怎么新建pytest的ini文件_pytest.ini配置前言pytest配置文件可以改变pytest的运行方式,它是一个固定的文件pytest.ini文件,读取配置信息,按指定的方式去运行查看pytest.ini的配置选项pytest-h找到以下


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

前言

pytest配置文件可以改变pytest的运行方式,它是一个固定的文件pytest.ini文件,读取配置信息,按指定的方式去运行
 

查看pytest.ini的配置选项

pytest -h

找到以下内容

[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:

  markers (linelist):   markers for test functions
  empty_parameter_set_mark (string):
                        default marker for empty parametersets
  norecursedirs (args): directory patterns to avoid for recursion
  testpaths (args):     directories to search for tests when no files or directories are given in the command line.
  filterwarnings (linelist):
                        Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.
  usefixtures (args):   list of default fixtures to be used with this project
  python_files (args):  glob-style file patterns for Python test module discovery
  python_classes (args):
                        prefixes or glob names for Python test class discovery
  python_functions (args):
                        prefixes or glob names for Python test function and method discovery
  disable_test_id_escaping_and_forfeit_all_rights_to_community_support (bool):
                        disable string escape non-ascii characters, might cause unwanted side effects(use at your own risk)
  console_output_style (string):
                        console output: "classic", or with additional progress information ("progress" (percentage) | "count").
  xfail_strict (bool):  default for the strict parameter of xfail markers when not given explicitly (default: False)
  enable_assertion_pass_hook (bool):
                        Enables the pytest_assertion_pass hook.Make sure to delete any previously generated pyc cache files.
  junit_suite_name (string):
                        Test suite name for JUnit report
  junit_logging (string):
                        Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|all
  junit_log_passing_tests (bool):
                        Capture log information for passing tests to JUnit report:
  junit_duration_report (string):
                        Duration time to report: one of total|call
  junit_family (string):
                        Emit XML for schema: one of legacy|xunit1|xunit2
  doctest_optionflags (args):
                        option flags for doctests
  doctest_encoding (string):
                        encoding used for doctest files
  cache_dir (string):   cache directory path.
  log_level (string):   default value for --log-level
  log_format (string):  default value for --log-format
  log_date_format (string):
                        default value for --log-date-format
  log_cli (bool):       enable log display during test run (also known as "live logging").
  log_cli_level (string):
                        default value for --log-cli-level
  log_cli_format (string):
                        default value for --log-cli-format
  log_cli_date_format (string):
                        default value for --log-cli-date-format
  log_file (string):    default value for --log-file
  log_file_level (string):
                        default value for --log-file-level
  log_file_format (string):
                        default value for --log-file-format
  log_file_date_format (string):
                        default value for --log-file-date-format
  log_auto_indent (string):
                        default value for --log-auto-indent
  faulthandler_timeout (string):
                        Dump the traceback of all threads if a test takes more than TIMEOUT seconds to finish.
  addopts (args):       extra command line options
  minversion (string):  minimally required pytest version
  required_plugins (args):
                        plugins that must be present for pytest to run
  base_url (string):    base url for the application under test.
  render_collapsed (bool):
                        Open the report with all rows collapsed. Useful for very large reports
  max_asset_filename_length (string):
                        set the maximum filename length for assets attached to the html report.
  rsyncdirs (pathlist): list of (relative) paths to be rsynced for remote distributed testing.
  rsyncignore (pathlist):
                        list of (relative) glob-style paths to be ignored for rsyncing.
  looponfailroots (pathlist):
                        directories to check for changes

 

注意

pytest一定要放在项目的根目录,名字也要命名为pytest.ini
 

mark标记

作用:测试用例中添加了 @pytest.mark.web装饰器,如果不添加marks选项的话,就会报warnings
写法

[pytest]
markers =
  app:  Run the app case
  web:  Run the web case

 

addopts

作用:addopts参数可以更改默认命令行选项,这个当我们在cmd输入一堆指令去执行用例的时候,就可以用该参数代替了,省去重复性的敲命令工作

比如:想测试完生成报告,失败重跑两次,如果在bash中写的话,命令会很长

pytest -v --reruns=2 --alluredir ./report --clean-alluredir

每次输入这么多,不太好记住,于是可以加到pytest.ini里

[pytest]
markers =
  app:  Run the app case
  web:  Run the web case
addopts = -v --reruns=2 --alluredir ./report --clean-alluredir

这样我下次打开cmd,直接输入pytest,它就能默认带上这些参数了
 

norecursedirs

作用:pytest 收集测试用例时,会递归遍历所有子目录,包括某些你明知道没必要遍历的目录,一般情况下项目的用例都放在case文件夹下,所以除了case文件夹,其他项目的路径都可以不必递归

默认设置: norecursedirs = .* build dist CVS _darcs {arch} *.egg
正确写法:在上面默认值后面加上除了case的所有路径,多个路径用空格隔开(一)

norecursedirs = .* build dist CVS _darcs {arch} *.egg API common configFile data logs report

 

自定义匹配规则

查看pytest -h 查看命令行参数找到 [pytest] ini-options

  • python_files (args) 匹配 python 用例文件, 如test_*.py、 *_test.py
  • python_classes (args) 匹配 class 类名称 如Test*.py
  • python_functions (args) 匹配函数和class里面方法 如test_*

假如我们想把匹配规则改为函数名以best_*开头

[pytest]

python_files =  test_*.py
python_classes = Test*
python_functions = best_*

这样以后pytest就匹配的都是以best开头的用例了

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/165986.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • SPPNet算法解析

    SPPNet算法解析前言沿着RCNN的思路,我们继续探索目标检测的痛点,其中RCNN使用CNN作为特征提取器,首次使得目标检测跨入深度学习的阶段。但是RCNN对于每一个区域候选都需要首先将图片放缩到固定的尺寸(224*224),然后为每个区域候选提取CNN特征。容易看出这里面存在的一些性能瓶颈:速度瓶颈:重复为每个regionproposal提取特征是极其费时的,SelectiveSearch对于每幅图…

    2022年5月13日
  • 3.7v锂电池升压电路_电池升压

    3.7v锂电池升压电路_电池升压FS2114的PCB布局设计建议-基础篇开关电源的一个常见问题是“不稳定”的开关波形。有时,波形抖动很明显,可以听到从磁性元件发出噪声。如果问题与印刷电路板(PCB)布局有关,则很难确定原因。EMC也是很注重(PCB)布局,这就是为什么在开关电源设计的早期正确布局PCB至关重要的原因。其重要性不可夸大。原理图走线主要器件放置并联一个旁路电容0.1uFLX节点FB反馈电阻R1,R2COUT电容容易影响输出的布线功率组件的推荐焊盘图案GND功率地的PCB布线电感器选择概述FS2

    2022年10月7日
  • 怎么使用matlab画图_matlab画图plot

    怎么使用matlab画图_matlab画图plot注意点matlab中分号;是拿来分隔列并抑制输出显示的。matlab中每个变量都是数组/矩阵,即使是x=1这样的语句也代表创建了一个1*1的矩阵,变量使用前必须有值。通过whos显示当前的变量使用情况。长任务可以通过使用省略号…扩展到另一行。formatlong命令显示十进制后的16位数字。b白色、r红色、k黑色基本语法示例循环、选择、函数定义function…

    2022年9月20日
  • 毕设/私活/必备,一个挣钱的标准开源前后端分离【springboot+vue+redis+Spring Security】脚手架–若依框架「建议收藏」

    目录java毕业设计项目《100套》推荐订阅前言:主要特性功能:内置功能模板:本地运行系统:后端运行:前端运行:必要配置:项目运行截图:登录:首页:菜单模块:用户绑定角色、角色控制菜单权限显示部门模块:通知公告:日志管理:项目文件结构:后端结构:前端结构:核心技术后端技术前端技术精彩java毕设实战项目推送java毕业设计项目《100套》推荐订阅前言:今天和大家分享一个是一个开源接私…

    2022年4月7日
  • 我的世界服务器指令大全电脑版_我的世界服务器专用指令

    我的世界服务器指令大全电脑版_我的世界服务器专用指令要成为一个合格的服主,熟悉我的世界服务器指令是必须的,服务器内指令的各种功能不仅是OP需要使用,还有部分是玩家也需要知道的,下面就看看小编为大家准备的我的世界服务器指令大全吧。【大全】我的世界服务器指令大全:首先/manuaddxxgm?如果要使用这个命令,需要自己先有权限在控制台输入manuaddxxadmin然后添加sethome权限manselect世界名字(默认world)输入m…

    2022年9月23日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号