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

相关推荐
独断万古他化41 分钟前
Python+Pytest 接口自动化测试实战 —— 抽奖系统接口测试框架设计与实现
python·pytest·接口自动化·测试·allure·yaml·json schema
小陈的进阶之路8 小时前
Selenium 常用操作 API
python·自动化·pytest
紫丁香8 小时前
pytest_自动化测试5
python·功能测试·单元测试·集成测试·pytest
姚青&8 小时前
Pytest fixture 参数化(params 参数)
开发语言·python·pytest
小张贼嚣张10 小时前
Pytest 核心特性与技术优势
pytest
姚青&10 小时前
Pytest 配置文件
pytest
姚青&17 小时前
Pytest 插件
pytest
姚青&21 小时前
Pytest 测试用例生命周期管理-yield
测试用例·pytest
紫丁香1 天前
pytest_自动化测试3
开发语言·python·功能测试·单元测试·集成测试·pytest
小罗和阿泽1 天前
接口测试系列 接口自动化测试 pytest框架(二)
pytest