前言

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

Pytest(14)pytest.ini配置文件的更多相关文章

  1. Python读取ini配置文件的方式

    python configparser模块   ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...

  2. 读取ini配置文件 及 UI对象库

    读取ini配置文件 配置项 读取API 写入API 实战:UI 对象库 读取ini配置文件 配置项 在每个 ini 配置文件中,配置数据会被分组(比如下述配置文件中的"config" ...

  3. DCMTK开源库的学习笔记4:利用ini配置文件对dcm影像进行归档

    转:http://blog.csdn.net/zssureqh/article/details/8846337 背景介绍: 医学影像PACS工作站的服务端需要对大量的dcm文件进行归档,写入数据库处理 ...

  4. 【个人使用.Net类库】(1)INI配置文件操作类

    开发接口程序时,对于接口程序配置的IP地址.端口等都需要是可配置的,而在Win Api原生实现了INI文件的读写操作,因此只需要调用Win Api中的方法即可操作INI配置文件,关键代码就是如何调用W ...

  5. 【Qt 】QSettings写ini配置文件

    QSettings写ini配置文件(Qt版本5.2): #include "inidemo.h" #include <QSettings> #include <Q ...

  6. c#读写ini配置文件示例

    虽然c#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧     其他人写的都是调用非托管kernel32.dll.我也用过 ...

  7. (转载)将DELPHI数据库连接写进INI配置文件中

    将DELPHI数据库连接写进INI配置文件中 procedure TDM.DataModuleCreate(Sender: TObject); var piececonfg:Tinifile; pat ...

  8. vb ——ini 配置文件

    最近在学校VB 开发点小东西, 使用ini配置文件要用到下边连个函数 GetPrivateProfileString (从配置文件得到信息)百度百科的介绍http://baike.baidu.com/ ...

  9. python 提供INI配置文件的操作 ConfigParser

    原文地址:http://www.cnblogs.com/pumaboyd/archive/2008/08/11/1265416.html 红色的为标注信息 +++++++++++++++++引用+++ ...

  10. 第四十二节,configparser特定格式的ini配置文件模块

    configparser用于处理特定格式的文件,其本质上是利用open来操作文件. 特定格式的ini配置文件模块,用于处理ini配置文件,注意:这个ini配置文件,只是ini文件名称的文本文件,不是后 ...

随机推荐

  1. Flutter 基础组件:单选框和复选框

    前言 Material组件库中提供了Material风格的单选开关Switch和复选框Checkbox,虽然它们都是继承自StatefulWidget,但它们本身不会保存当前选中状态,选中状态都是由父 ...

  2. 基于SVM的字母验证码识别

    基于SVM的字母验证码识别 摘要 本文研究的问题是包含数字和字母的字符验证码的识别.我们采用的是传统的字符分割识别方法,首先将图像中的字符分割出来,然后再对单字符进行识别.首先通过图像的初步去噪.滤波 ...

  3. maven 的安装与配置详细步骤

    1. 直接搜索maven 2. 进入后点击download界面,这时出现的是当前最新版本, 当然还有以前的版本可供下载 3. 下载解压到你指定的目录后,需要配置一下环境变量. a. 右键此电脑点击属性 ...

  4. Azure Terraform(五)利用Azure DevOps 实现自动化部署基础资源

    一,引言 上一篇我们结合学习 Azure Traffic Manger 的内容,做了一个负载均衡的基础设施架构.通过 Terraform 部署执行计划,将整个 Azure Traffic Manage ...

  5. 【ORA】ORA-00257 archiver error. 错误的处理方法

    今天连接数据库,结果报错,ora-00257查看 [oracle@exam oracle]$ oerr ora 00257 00257, 00000, "archiver error. Co ...

  6. 【小菜学网络】交换机与MAC地址学习

    上一小节介绍了 集线器 ,一种工作于物理层的简单网络设备.由于集线器采用广播的方式中继.转发物理信号,传输效率受到极大制约. 精准转发 为了解决集线器工作效率低下的尴尬,我们需要设计一种更高级的网络设 ...

  7. 1.2V升压到3V和3.3V的升压芯片

    1.2V镍氢电池升压到3V和3.3V输出,1.2V升压3V,1.2V升压3.3V稳压输出供电的芯片. PW5100 是一款低静态电流.达效率. PFM 模式控制的同步升压变换器. PW5100 所需的 ...

  8. SQL Server 2012 忘记sa用户处理方法

    SQL Server 2012 忘记sa用户的密码,可重置sa密码,方法如下: 1.将身份验证改成Windows身份验证,登录进去 2.进入SQL Server控制台,在对象资源管理器中找到Secur ...

  9. Kafka分区分配策略(Partition Assignment Strategy)

    众所周知,Apache Kafka是基于生产者和消费者模型作为开源的分布式发布订阅消息系统(当然,目前Kafka定位于an open-source distributed event streamin ...

  10. linux设备注册

    一.分配cdev cdev表示字符设备,使用cdev_alloc函数,cdev_alloc函数原型如下: /** * cdev_alloc() - allocate a cdev structure ...