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')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)