Pytest(14)pytest.ini配置文件

pytest配置文件可以改变pytest的运行方式,它是一个固定的文件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

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

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

作用: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,它就能默认带上这些参数了

作用: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开头的用例了

Original: https://blog.csdn.net/weixin_43880991/article/details/116221351
Author: Silent丿丶黑羽
Title: Pytest(14)pytest.ini配置文件

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/776770/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Pytorch避坑之:RuntimeError: Input type(torch.cuda.FloatTensor) and weight type(torch.FloatTensor) shoul

    问题分析 就像是字面意思那样,这个错误是因为模型中的 weights 没有被转移到 cuda 上,而模型的数据转移到了 cuda 上而造成的 但是造成这个问题的原因却没有那么简单。…

    Python 2023年8月2日
    043
  • Bootstrap5 如何创建多媒体对象

    一、在Bootstra5中使用媒体对象 Bootstrap 媒体对象在版本 5 中已经停止支持了。但是,我们仍然可以使用 flex 和 margin 创建包含左对齐或右对齐媒体对象…

    Python 2023年6月9日
    079
  • Pygame实现小笨鸟,到小飞鸟

    在B站学习UP主: 趣派编程,” 99%相似度!手把手教你用Python制作Flappy Bird像素鸟游戏!” 后有感而发。 在UP主: 趣派编程,做的项…

    Python 2023年8月10日
    045
  • Pytest接口测试框架实战项目搭建(三)

    一、前言 前面相当于已经讲完整体框架搭建了,本篇主要讲述在实际业务系统的接口请求中,如何运用好该接口自动化测试框架。 二、步骤演示 1、在conf/api_path.py新增需要测…

    Python 2023年9月12日
    044
  • 今年,我只赚了一点点

    大家好,我是 Jack。 之前一直有小伙伴问我,有没有免费的股票信息查询的 API 接口? 我看了一圈,很多免费的 API 接口都年久失修,失效了。 那好吧, 咱自己写一个。 想要…

    Python 2023年9月26日
    033
  • Python代码阅读(第43篇):构造组合函数

    本文中的代码实现了一个复合函数的构造,该复合函数依次调用输入函数。 [En] The code read in this article implements the constr…

    Python 2023年5月24日
    074
  • ELK日志系统搭建

    文章目录 ES * 安装ES 启动ES 错误处理 验证 Kibana * 安装Kibana 启动 Kibana Logstash * 安装Logstash 启动Logstash 项…

    Python 2023年10月10日
    043
  • 小熊飞桨练习册-05水果数据集

    文件说明 文件 说明 train.py 训练程序 test.py 测试程序 test-gtk.py 测试程序 GTK 界面 report.py 报表程序 onekey.sh 一键获…

    Python 2023年10月26日
    038
  • 写给初入职场小白的建议

    昨天加班处理问题,今天可以休息了,借着这个空当想总结一下本人工作三年的工作经验,以及给初入职场小白一些建议,和本人对安全行业的认识。 首先,想问一下各位,您第一份正式工作想得到什么…

    Python 2023年6月11日
    059
  • Numpy系列(五):函数库之2随机数及概率分布

    Numpy系列目录 文章目录 一、 简介 二、 思维导图 三、 Numpy随机数及概率分布 * 1. 随机数 – 1.1 api版本说明 1.2 简单随机数 1.3 设…

    Python 2023年8月27日
    068
  • 【Python】np.unique() 介绍与使用

    文章目录 一、np.unique() 介绍 二、np.unique() 原型 三、实例 参考链接 一、np.unique() 介绍 对于一维数组或者列表,np.unique() 函…

    Python 2023年8月1日
    095
  • Python基础之day11-模块

    抵扣说明: 1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。 Original: https://blo…

    Python 2023年9月25日
    048
  • pytest单元测试框架基础知识

    一、pytest单元测试框架 单元测试是指在软件开发中,针对软件的最小单位(函数、方法)进行正确性的检查测试 Java:Junit和testing Python:UNItest和p…

    Python 2023年9月13日
    041
  • 牛客前端刷题(十)—— 设计模式篇

    啊哦~你想找的内容离你而去了哦 内容不存在,可能为如下原因导致: ① 内容还在审核中 ② 内容以前存在,但是由于不符合新 的规定而被删除 ③ 内容地址错误 ④ 作者删除了内容。 可…

    Python 2023年10月27日
    024
  • python_缺失值处理

    Data Cleaning and Preparation# pandas使⽤浮点值# NaN(Not a Number)表示缺失数据。我们称其为哨兵值import numpy a…

    Python 2023年5月25日
    078
  • Maximum Entropy Population-Based Training for Zero-Shot Human-AI Coordination

    原文:https://www.cnblogs.com/Twobox/p/16791412.html 熵 熵:表述一个概率分布的不确定性。例如一个不倒翁和一个魔方抛到地上,看他们平稳…

    Python 2023年10月28日
    049
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球