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

相关推荐
零基础的修炼5 小时前
自动化测试---pytest
pytest
鲜于言悠9051 天前
博客系统测试报告
python·功能测试·selenium·jmeter·测试用例·集成测试·pytest
0和1的舞者2 天前
高并发论坛系统:单元测试 + 接口自动化 + 性能测试 + CI/CD 全链路测试报告
java·测试开发·测试工具·jmeter·pytest·测试·测试报告
独断万古他化2 天前
Python+Pytest 搭建博客系统接口自动化测试框架(全用例执行+完整代码)
pytest·接口自动化·测试·allure·requests
王夏奇2 天前
python-pytest学习
python·学习·pytest
独断万古他化3 天前
Python 接口测试之 requests 库核心用法
python·pytest·接口测试·requests
姚青&3 天前
Pytest 测试用例生命周期管理-fixture
测试用例·pytest
姚青&17 天前
PyCharm 配置与界面化运行
pytest
姚青&17 天前
Pytest 测试用例断言
测试用例·pytest
姚青&17 天前
Pytest 命名规则
pytest