关于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.采用英文名

相关推荐
纯纯沙口10 分钟前
pytest - 基础使用教程
pytest
问道飞鱼6 小时前
【自动化测试】pytest 语法与核心概念
自动化测试·pytest·playwright
zUlKyyRC7 小时前
基于一阶RC模型,FFRLS+EKF算法的电池SOC在线联合估计Matlab程序
pytest
我的xiaodoujiao2 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 40--完善优化 Allure 测试报告显示内容
python·学习·测试工具·pytest
我的xiaodoujiao2 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 41--自定义定制化展示 Allure 测试报告内容
python·学习·测试工具·pytest
nvd112 天前
Pytest 异步数据库测试实战:基于 AsyncMock 的无副作用打桩方案
数据库·pytest
nvd113 天前
深入分析:Pytest异步测试中的数据库会话事件循环问题
数据库·pytest
程序员雷叔3 天前
在postman设置请求里带动态token,看看这两种方法!
selenium·测试工具·单元测试·测试用例·pytest·lua·postman
花酒锄作田4 天前
[python]Flask - Tracking ID的设计
python·flask·pytest
测试秃头怪4 天前
Python测试框架Pytest的参数化
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest