关于pytest中用例名称使用中文乱码的解决

场景:使用@pytest.mark.parametrize装饰器为用例自定义名称时,运行显示乱码。如下图所示:

解决方案:

1.在根目录 pytest.ini中增加一行代码

复制代码
[pytest]
disable_test_id_escaping_and_forfeit_all_rights_to_community_support=True

2.在conftest.py中加入钩子函数

复制代码
def pytest_collection_modifyitems(items):
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")

3.采用英文名

相关推荐
问道飞鱼2 分钟前
【自动化测试】 pytest 结合 Playwright 实现页面元素在两个区域间拖拽
pytest·拖拽·playweight
先鱼鲨生26 分钟前
自动化框架pytest
运维·自动化·pytest
程序员杰哥20 小时前
Pytest自动化测试框架实战
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
Yorlen_Zhang2 天前
Python pytest assert 断言
python·servlet·pytest
纯纯沙口4 天前
pytest - 基础使用教程
pytest
问道飞鱼4 天前
【自动化测试】pytest 语法与核心概念
自动化测试·pytest·playwright
zUlKyyRC4 天前
基于一阶RC模型,FFRLS+EKF算法的电池SOC在线联合估计Matlab程序
pytest
我的xiaodoujiao6 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 40--完善优化 Allure 测试报告显示内容
python·学习·测试工具·pytest
我的xiaodoujiao6 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 41--自定义定制化展示 Allure 测试报告内容
python·学习·测试工具·pytest