0
点赞
收藏
分享

微信扫一扫

pytest.ini应用----定制pytest命令的默认行为


​​pytest(1)安装以及快速入门​​

​​pytest(2)默认用例命名规则​​

​​pytest(3)各个层级的setup和teardown详解​​

​​pytest(4)失败的用例重新执行​​

​​pytest(5)多进程并行执行用例​​

​​pytest(6)失败N次后停止执行​​

​​pytest(7)fixture详解​​

​​pytest(8-1)win10安装配置allure​​

​​pytest(8-2)CentOS7安装配置allure​​

​​pytest(9)生成allure执行报告​​

​​pytest(10)参数化详解​​

​​pytest(11)allure报告定制样式​​

​​pytest(12)allure报告定制logo​​

​​pytest(13)定制自定义命令行参数​​

​​pytest(15)标签mark使用详解​​

​​pytest.ini应用----自定义测试文件、测试用例、测试类命名规则​​

​​pytest.ini应用----消除mark标签产生的告警​​

​​pytest.ini应用----定制pytest命令的默认行为​​

​​pytest.ini应用----指定搜索脚本路径​​

​​pytest(19)repeat插件详解​​

在执行pytest用例的过程中,可能会有一些默认都会用的命令行,比如 -s 显示信息,生成allure日志等命令,如果每次执行脚本都需要执行一长串命令,也是挺麻烦的,pytest提供了一种方式,可以修改pytest命令的默认行为,类似Linux命令种的别名一样,通过配置,即可做到执行pytest命令,不加任何参数,默认却带了一大推的默认操作参数

  • 比如这里希望 pytest -s --alluredir=./temp 命令中的-s和生成allure日志的行为为默认行为,即可定义pytest命令的默认行为就是执行pytest -s --alluredir=./temp 命令
  • 在根目录创建 pytest.ini文件,然后在pytest.ini中配置如下内容:

[pytest]
addopts=-s --alluredir=./temp

  • 然后在终端中执行pytest命令

pytest

执行结果如下:

G:\redrose2100\src\demo>pytest
========================================================================== test session starts ===========================================================================
platform win32 -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: G:\redrose2100\src\demo, configfile: pytest.ini
plugins: allure-pytest-2.9.43, rerunfailures-10.0
collected 1 item

test_example.py in test_demo...
.

============================================================================ warnings summary ============================================================================
test_example.py:3
G:\redrose2100\src\demo\test_example.py:3: PytestUnknownMarkWarning: Unknown pytest.mark.smoke - is this a typo? You can register custom marks to avoid this warning - f
or details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.smoke

test_example.py:7
G:\redrose2100\src\demo\test_example.py:7: PytestUnknownMarkWarning: Unknown pytest.mark.smoke - is this a typo? You can register custom marks to avoid this warning - f
or details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.smoke

test_example.py:8
G:\redrose2100\src\demo\test_example.py:8: PytestUnknownMarkWarning: Unknown pytest.mark.function - is this a typo? You can register custom marks to avoid this warning
- for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.function

test_example.py:12
G:\redrose2100\src\demo\test_example.py:12: PytestUnknownMarkWarning: Unknown pytest.mark.function - is this a typo? You can register custom marks to avoid this warning
- for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.function

-- Docs: https://docs.pytest.org/en/stable/warnings.html
===================================================================== 1 passed, 4 warnings in 0.02s ======================================================================

G:\redrose2100\src\demo>

此时,目录中生成了temp文件及以及allure日志内容

pytest.ini应用----定制pytest命令的默认行为_用例


举报

相关推荐

0 条评论