Pytest学习笔记(6)-配置文件pytest.ini

文章目录

    • 配置文件pytest.ini
      • 前言
      • 常用配置项
        • markers
        • testpaths
        • addopts
        • xfail_strict
        • log_cli
        • norecursedirs
        • 更改测试用例收集规则
      • 注意事项

配置文件pytest.ini

前言

很多 pytest settings 可以设置在 配置文件 ,它通常位于存储库的根目录或测试文件夹中

pytest.ini 文件优先于其他文件,即使是空的

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

常用配置项

markers

它的作用是做注册标记,防止拼写错误。比如把@pytest.mark.smoke拼成@pytest.mark.somke,默认情况下。这不会引起程序错误。pytest会以为这是你创建的另一个标记。为了避免拼写错误。可以在pytest.ini文件里注册标记

[pytest]
# 注册自定义标记
markers =
    smoke: Run the smoke test functions for tasks project
    get: Run the test functions that test tasks.get()

标记注册好后,可以通过pytest --markers来查看
Pytest学习笔记(6)-配置文件pytest.ini_第1张图片

testpaths

testpaths指示pytest去哪里访问。testpaths是一系列相对于根目录的路径,用于限定测试用例的搜索范围。只有在pytest未指定文件目录参数或测试用例标识符时,该选项才有作用,举个:

修改pytest.ini文件如下:

[pytest]
testpaths = test_02.py

修改test_01.py test_02.py文件如下:

# FileName: test_01.py
import pytest

def test_01(fixturedemo):
    print('

你可能感兴趣的:(Pytest学习笔记,python,测试用例,开发语言)