目录

前言

查看选项

使用方式

常用配置项

注意事项


前言

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

查看选项

  • pytest  --help
[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:markers (linelist):   markers for test functionsempty_parameter_set_mark (string):default marker for empty parametersetsnorecursedirs (args): directory patterns to avoid for recursiontestpaths (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 projectpython_files (args):  glob-style file patterns for Python test module discoverypython_classes (args):prefixes or glob names for Python test class discoverypython_functions (args):prefixes or glob names for Python test function and method discoverydisable_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 ownrisk)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 cachefiles.junit_suite_name (string):Test suite name for JUnit reportjunit_logging (string):Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|alljunit_log_passing_tests (bool):Capture log information for passing tests to JUnit report:junit_duration_report (string):Duration time to report: one of total|calljunit_family (string):Emit XML for schema: one of legacy|xunit1|xunit2doctest_optionflags (args):option flags for doctestsdoctest_encoding (string):encoding used for doctest filescache_dir (string):   cache directory path.log_level (string):   default value for --log-levellog_format (string):  default value for --log-formatlog_date_format (string):default value for --log-date-formatlog_cli (bool):       enable log display during test run (also known as "live logging").log_cli_level (string):default value for --log-cli-levellog_cli_format (string):default value for --log-cli-formatlog_cli_date_format (string):default value for --log-cli-date-formatlog_file (string):    default value for --log-filelog_file_level (string):default value for --log-file-levellog_file_format (string):default value for --log-file-formatlog_file_date_format (string):default value for --log-file-date-formatlog_auto_indent (string):default value for --log-auto-indentfaulthandler_timeout (string):Dump the traceback of all threads if a test takes more than TIMEOUT seconds to finish.addopts (args):       extra command line optionsminversion (string):  minimally required pytest versionrequired_plugins (args):plugins that must be present for pytest to runrender_collapsed (bool):Open the report with all rows collapsed. Useful for very large reportsmax_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.ini (不要改名字)
  • 存放位置:放在项目根目录下

常用配置项

  • markers:注册自定义标签,主要解决自定义标记的warnings提示信息。
  • xfail_strict:让那些标记为@pytest.mark.xfail但实际通过显示XPASS的测试用例被报告为失败
  • addops:命令行参数
  • log_cli:控制台输出日志
  • norecursedirs:收集测试用例时,跳过的目录

# pytest.ini [pytest]# 命令行参数 -v 详细打印 -s 打印调试信息   失败重跑两次   一共运行两次
addopts = -v -s --reruns=1 --count=2# 注册mark
markers=web: web 测试用例app: app 测试用例# 指定测试case路径
testpaths = testcase/# 忽略的搜索路径
norecursedirs = evn reports/# 搜索用例规则,测试类、测试文件、测试方法
python_files =     test_*  *_test  test*
python_classes =   Test*   test*
python_functions = test_*  test*# 控制台输出日志
log_cli=1# 设置控制台日志信息
log_cli_level=info
log_cli_date_format=%Y-%m-%d-%H-%M-%S
log_cli_format=%(asctime)s-%(filename)s-%(module)s-%(funcName)s-%(lineno)d-%(levelname)s-%(message)s# 设置日志文件信息
log_file=test.log
log_file_level=INFO
log_file_date_format=%Y-%m-%d %H:%M:%S
log_file_format=%(asctime)s %(filename)s %(module)s %(funcName)s %(lineno)d %(levelname)s: %(message)s

注意事项

  • pytest.ini 文件里面不能使用任何中文符号,包括汉字、空格、引号、冒号等;

18-pytest-配置文件pytest.ini使用相关推荐

  1. pytest配置文件pytest.ini

    Python微信订餐小程序课程视频 https://edu.csdn.net/course/detail/36074 Python实战量化交易理财系统 https://edu.csdn.net/cou ...

  2. 2022最新最全的pytest配置文件pytest.ini

    说明: pytest.ini是pytest的全局配置文件,一般放在项目的根目录下 是一个固定的文件-pytest.ini 可以改变pytest的运行方式,设置配置信息,读取后按照配置的内容去运行 点我 ...

  3. 【pytest】pytest配置文件pytest.ini详解

    文章目录 前言 pytest.ini的内容构成 配置项markers 配置项testpaths 配置项addopts 前言 说到配置,大家可能想到的是不经常更改的内容,比如Django里的settin ...

  4. 测试学习总结之---Pytest配置文件和标记

    Pytest配置文件 pytest的配置文件通常放在测试目录下,名称为pytest.ini,命令运行时会使用该配置文件中的配置 配置文件时以 [pytest] 开头 ,pytest.ini文件格式示例 ...

  5. pytest十三:配置文件 pytest.ini

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

  6. 什么是Pytest及Pytest常用方法

    什么是Pytest? 一.什么是pytest 二.Pytest的特点 三.Pytest以及常用插件安装 四.编写规则 五.Pytest之收集用例及命令行参数 1.用例收集规则 2.命令行参数 六.跳过 ...

  7. python读取配置文件存在某配置_Python读取配置文件(config.ini)以及写入配置文件

    一.读取配置文件 我的目录如下,在config下有一个config.ini配置文件 配置文件内容# 定义config分组 [config] platformName=Android appPackag ...

  8. 获取php.ini配置信息,获得php所对应的配置文件(php.ini)信息

    获得php所对应的配置文件(php.ini)信息 [root@BIND9-master /usr/local/bin]# php --ini Configuration File (php.ini) ...

  9. 如何查找 MySQL配置文件 my.ini (my.conf)的位置(案例篇)

    如何查找 MySQL配置文件 my.ini (my.conf)的位置(案例篇) MySQL配置文件说明:[系统不同,后缀有区别] MySQL配置文件在Windows下叫my.ini,在MySQL的安装 ...

  10. php查看其配置文件路径,php配置文件php.ini所在路径如何查看?

    告诉大家查找php配置文件php.ini所在路径的二种方法. 通常php.ini的位置在: /etc目录下或/usr/local/lib目录下. 如果你还是找不到php.ini或者找到了php.ini ...

最新文章

  1. Java基础学习三:循环结构的使用
  2. 澳大利亚悉尼科技大学招收人工智能/软件工程方向全奖博士生
  3. SAP MM 物料主数据MRP2 视图’Minimum Lot Size’字段
  4. go语言中无法获取goroutine相关的信息
  5. 配置环境将win32项目移植到Android
  6. timestamp类型设置默认时间
  7. java 短链跳转原理_给你代码:短链接生成原理
  8. [翻译]编写高性能 .NET 代码 第一章:性能测试与工具 -- 选择什么来衡量
  9. NanShan开源即时通讯团队讨论程序员空闲期可以做的事
  10. 前端面试宝典(3)——其他
  11. MCPC 2011Hdu4207-4214(未完全)题解
  12. 逆发动机模型map图制作
  13. pr怎么导出预设_怎样用Pr导出清晰度高的视频?
  14. OpenBmc开发5:bitbake介绍与使用
  15. 数据传输完整性_数据集成:什么是数据完整性?
  16. 世界上第一次网络瘫痪 | 历史上的今天
  17. 如何在线免费对PDF文档进行解密
  18. HTML英雄联盟 效果图代码结构 (多多指教,感谢)
  19. java.io.IOException: 远程主机强迫关闭了一个现有的连接
  20. 多种方法进行去基线处理

热门文章

  1. C++入门到精通(xcode IDE)
  2. 事实上已经有一些职业正在被人工智能所取代
  3. 根据年份提取dblp内容
  4. JavaScript进阶(4)-dom查询
  5. 《SQL Server2008R2数据挖掘与商业智能》实例——决策树
  6. 天津工业大学信息与计算机学院,图象与信息技术研究所
  7. 浏览器渲染类型2d 3d_Google在浏览器中提供3D渲染
  8. Java Spring Cloud XII 之 单点登录
  9. 计算机网络 自顶向下(5)链路层——学习笔记
  10. 什么是Crunchyroll,它提供什么动漫?