python-pytest.ini介绍

一、pytest.ini执行方式含义

[pytest]
addopts = -vsq  --html=./report.html
testpaths = ./testConftest
python_files = test*.py
python_classes = Test*
python_functions = test*
log_cli=True
norecursedirs = venv report assets
markers = datafile

# 1.addopts–设置自定义执行参数 addopts = -s --reruns 1 --html=report.html
#     -v: 显示错误位置以及错误的详细信息
#     -s: 等价于 pytest --capture=no 可以捕获print函数的输出
#     -q: 简化输出信息
#     -m: 运行指定标签的测试用例
#     -x: 一旦错误,则停止运行
# 2.testpaths–设置执行路径
# 3.修改匹配规则  python_files =  test*.py
# 4.norecursedirs 用例收集过滤不需要的目录
# 5.log_cli 控制台实时输出日志
# 6.markers–标记分组参数

 

二、处理控制台输出、报告输出中文乱码

[pytest]
disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True   #中文乱码

或者

conftest.py 

def pytest_collection_modifyitems(items):
    """
    修改用例名称中文乱码
    :param items:
    :return:
    """
    for item in items:
        item.name = item.name.encode('utf-8').decode('unicode_escape')
        item._nodeid = item.nodeid.encode('utf-8').decode('unicode_escape')

 

posted @ 2023-02-05 15:44  南方的墙  阅读(53)  评论(0编辑  收藏  举报