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

相关推荐
思则变1 小时前
[Pytest][Part 3]检测python package状态
pytest
cooldream200914 天前
pytest 框架详解与实战指南
pytest·测试
慕城南风14 天前
【pytest进阶】Pytest之conftest详解
pytest
编程小白gogogo15 天前
AI自动化测试速成(Pytest框架)
pytest
慕城南风15 天前
【pytest进阶】pytest详解及进阶使用
linux·服务器·pytest
Tom Boom22 天前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest
不要一直敲门24 天前
初学 pytest 记录
pytest
测试界清流24 天前
Selenium4+Pytest自动化测试框架
selenium·测试工具·pytest
努力搬砖的咸鱼1 个月前
从零开始搭建 Pytest 测试框架(Python 3.8 + PyCharm 版)
python·pycharm·pytest