1.Pytest配置文件能够改变Pytest框架代码的运行规则,比如修改Pytest收集用例的规则,添加命令行参数等等!

2.pytest --help:通过命令pytest --help查看配置文件中可以添加的一些参数及选项,这些选项都是可以添加到pytest的配置文件的。

[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 direconsole_output_style (string) console output: classic or with additional progrusefixtures (args)       list of default fixtures to be used with this projectpython_files (args)      glob-style file patterns for Python test module discopython_classes (args)    prefixes or glob names for Python test class discoverpython_functions (args)  prefixes or glob names for Python test function and mdisable_test_id_escaping_and_forfeit_all_rights_to_community_support (bool) dixfail_strict (bool)      default for the strict parameter of xfail markers whejunit_suite_name (string) Test suite name for JUnit reportjunit_logging (string)   Write captured log messages to JUnit report: one of njunit_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.filterwarnings (linelist) Each line specifies a pattern for warnings.filterwarlog_print (bool)         default value for --no-print-logslog_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 "lilog_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-formataddopts (args)           extra command line optionsminversion (string)      minimally required pytest versionenvironment variables:PYTEST_ADDOPTS           extra command line optionsPYTEST_PLUGINS           comma-separated plugins to load during startupPYTEST_DISABLE_PLUGIN_AUTOLOAD set to disable plugin auto-loadingPYTEST_DEBUG             set to enable debug tracing of pytest's internalsto see available markers type: pytest --markers
to see available fixtures type: pytest --fixtures
(shown according to specified file_or_dir or current dir if not specified; fixtures with leading '_' are only shown with the '-v' option

3.file:通常情况下把配置文件放到项目根目录下命名为 pytest.ini, 项目在运行时会首先按照配置文件中设置的参数选项来运行,其次再遵守pytest的默认规则。

3.1.添加默认参数选项:pytest可以在cmd中使用命令行运行脚本。通过pytest -vqs命令来运行脚本。

G:\PytestBasics\testone>pytest -vqs
============================= test session starts =============================
platform win32 -- Python 2.7.15, pytest-4.6.6, py-1.8.0, pluggy-0.12.0
rootdir: G:\PytestBasics\testone
plugins: allure-pytest-2.8.0, html-1.21.1, metadata-1.8.0, rerunfailures-7.0
collected 4 items                                                              test_module_one.py 我是一个测试用例! in test_testFunc1
.
test_module_three.py 我是一个测试用例! in test_testFunc4
.我是一个类里面的测试用例 in test_class_func3
.
test_module_two.py 我是一个类里面的测试用例 in test_class_func1
.
========================== 4 passed in 0.11 seconds ===========================

4.先在项目根目录下新建pytest.ini文件并配置选项

4.1.再次运行脚本仅通过命令pytest即可,这时候发现输出信息和上面一摸一样,这就是配置文件的作用。

[pytest]
addopts=-vqs

5.添加用例路径

5.1.通过配置可以把用例所在的目录添加到配置文件,在运行用例的时候,pytest会直接在配置文件所在的目录搜索用例。

[pytest]
testpaths=./testone

6.指定pytest的版本。

[pytest]
minversion = 3.0

7.指定pytest忽略哪些搜索目录

7.1.其中*.egg dist build部分为系统默认不会搜索的路径,前面是用户自定义的路径。注:当自定义时最好把系统默认的添加到后面。

[pytest]
norecursedirs = .* venv src *.egg dist build

8.修改pytest收集用例的规则-测试类

8.1.pytest默认搜索以test_开头/以_test结尾的文件,以Test开头的类,且以test_开头的测试函数为测试用例。

8.2.搜索以Test*开头,Test结尾或者Suite开头或结尾的类名字,需要添加这样的选项。

[pytest]
python_classes = *Test Test* *Suite

9.修改pytest收集用例规则-修改测试模块。
9.1.搜索以check_*开头的文件。

[pytest]
python_files=test_* *_test check_*

10.修改pytest收集用例规则-修改测试方法。

10.1.搜索以check_* 开头的测试函数为测试用例。

[pytest]
python_functions = test_* *_test check_*

11.添加生成报告选项

[pytest]
addopts = -v --rerun 1 --html=report.html --self-contained-html

12.添加mark标记

12.1.通常在编写测试用例的时候,会在用例上回添加一些标记来记录哪些用例需要运行,哪些需要跳过,哪些需要标记为failed等等,那么难免记不住这些标记,可以通过配置文件记录这些标记。

[pytest]
markers=loginTest: Run login test casescontactTest: Run add contact test casessendMailTest: Run send mail test cases

12.2.添加完这些标记之后,通过pytest --markers查看mark。

D:\PytestAutoTestFrameWork\TestCases>pytest --markers
@pytest.mark.loginTest: Run login test cases@pytest.mark.contactTest: Run add contact test cases@pytest.mark.sendMailTest: Run send mail test cases@pytest.mark.flaky(reruns=1, reruns_delay=0): mark test to re-run up to 'reruns' times. Add a delay of 'reruns_delay' seconds between re-runs.@pytest.mark.filterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings@pytest.mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.

第十二:Pytest进阶之配置文件相关推荐

  1. SQLite入门到精通之十二:进阶3:特殊指令:PRAGMA|Join|Unions|Alter

    SQLite PRAGMA SQLite 的 PRAGMA 命令是一个特殊的命令,可以用在 SQLite 环境内控制各种环境变量和状态标志.一个 PRAGMA 值可以被读取,也可以根据需求进行设置. ...

  2. lisp算零碎面积总和_Common Lisp:符号计算简单介绍(第十二章)

    第十二章 结构体和类型系统(Structures and The Type System) 12.1 导语 Common Lisp包含了很多内建的数据类型,他们一起形成了一个类型系统.我们到现在为止学 ...

  3. 项目十二做好计算机维护,电脑组装与维护教学课件 项目十二 电脑组装和维护进阶.ppt...

    <电脑组装与维护教学课件 项目十二 电脑组装和维护进阶.ppt>由会员分享,可在线阅读,更多相关<电脑组装与维护教学课件 项目十二 电脑组装和维护进阶.ppt(33页珍藏版)> ...

  4. 实验二十二 SCVMM中的SQL Server配置文件

    实验二十二 SCVMM中的SQL Server配置文件 在VMM 2012中管理员可以使用 SQL Server 配置文件,在部署完成虚拟机之后,实现 SQL Server 数据库服务自动化部署并交付 ...

  5. Python 进阶之路 (十二) 尾声即是开始

    Python进阶之路总结 大家好,我的<< Python进阶之路>>到这一期就到此为止了,和 <<Python 基础起步>>不同,在掌握了一些基础知识后 ...

  6. Shiro第十二章-与Spring集成、配置文件初解

    简介 Shiro的组件都是Javabean/pojo式的组件,所以非常容易使用Spring进行组件管理,可以非常方便得从ini配置转为Spring配置(如xml配置文件). JavaSE 依赖 < ...

  7. JVM进阶(十二)——JAVA 可视化分析工具

    JVM进阶(十二)--JAVA 可视化分析工具   经过前几篇博文对堆内存以及垃圾收集机制的学习,相信小伙伴们已经建立了一套比较完整的理论体系!本篇博客就根据已有的理论知识,通过可视化工具来实践一番. ...

  8. 第十二课 Java基础篇——面向对象进阶(一)

    一.Static static表示静态,是Java中的一个修饰符,可以修饰成员方法,成员变量 静态变量是随着类的加载而加载的,优先于对象出现的 练习1.定义数组工具类 需求:在实际开发中,经常会遇到一 ...

  9. DevOps进阶(十二)GIT、GITLAB、GITHUB、GITLIB

    DevOps进阶(十二)GIT.GITLAB.GITHUB.GITLIB Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git是一个开源的分布式版本控制系统,可以 ...

最新文章

  1. android+tv+自动切换,Android TV 重写GridView,实现焦点放大效果
  2. 数据解读:资本追逐的14个人工智能细分领域
  3. Android 2D游戏引擎AndEngine配置环境
  4. SqlServer跨集群升级
  5. 什么是物联网?—Vecloud 微云
  6. Oracle(21)—— Linux环境部署Oracle11g数据库
  7. 亲测有效的网易云音乐歌单转换到apple music 的方法!
  8. iOS-状态栏字体颜色【白色】【Xcode9.1】
  9. python 学习资料
  10. 记:从百度空间搬家到博客园--写博客要写的舒服
  11. 熬之滴水穿石:Spring--精简的J2EE(5)
  12. ajax请求进error怎么弹出错诶信息,在ajax请求jqgrid之后出现错误时显示错误消息...
  13. 【WP8】WebBrowser相关
  14. FAT12文件系统详解
  15. 农夫山泉CIO分享SAP HANA数据库实施经验
  16. “搭讪学” 这不仅仅是泡妞
  17. 西部狂徒自建服务器,在《西部狂徒》中如何快速建立自己根据地?杀人放火是上策...
  18. dell G7 7588安装ubuntu双系统
  19. setenv设置环境变量_setenv命令教程在Linux中添加,删除和更改环境变量
  20. 如何从乱码中恢复 (下)?

热门文章

  1. 转载: CentOS下配置Apache
  2. liunx trac 插件使用之GanttCalendarPlugin
  3. leetcode-反转整数
  4. 机器学习之01篇:初步窥探
  5. winform 图片集合
  6. SSIS 连接ORACLE 无法从 SQL 命令中提取参数的解决方案
  7. 《java入门第一季》之类面试题
  8. Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案
  9. 在同一个类中,一个方法调用另外一个有注解(比如@Async,@Transational)的方法,注解失效的原因和解决方法
  10. PHP no input file specified 三种解决方法