关于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】使用Allure生成企业级测试报告
python·pytest
少云清16 小时前
【接口测试】4_代码实现 _pytest框架
pytest·接口测试
屋顶那猫17 小时前
使用pyinstaller打包pytest项目
python·pytest
zyx没烦恼2 天前
pytest框架
pytest
兴趣使然黄小黄4 天前
【Pytest】Pytest常用的第三方插件
python·pytest
我的xiaodoujiao4 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 34--基础知识 9--文件上传功能
前端·python·测试工具·ui·pytest
我一定会有钱4 天前
pytest测试框架基础
python·单元测试·自动化·pytest
我的xiaodoujiao4 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 35--二次封装MySQL数据库连接操作
python·学习·测试工具·pytest
给你一页白纸5 天前
Pytest 测试用例自动生成:接口自动化进阶实践
python·pytest·接口自动化
工会主席-阿冰5 天前
使用pytest-selenium插件,ui自动化示例
selenium·pytest