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

相关推荐
我的xiaodoujiao13 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 31--开源电商商城系统项目实战--加入购物车、提交订单测试场景
python·学习·测试工具·pytest
我的xiaodoujiao19 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 30--开源电商商城系统项目实战--配置测试环境地址
python·学习·测试工具·pytest
旦莫3 天前
Pytest教程: Pytest ini配置文件深度剖析
python·单元测试·自动化·pytest
Mr_Xuhhh7 天前
pytest -- 测试报告allure
pytest
我的xiaodoujiao8 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 28--开源电商商城系统项目实战--封装注册页面
python·学习·测试工具·pytest
Mr_Xuhhh8 天前
pytest -- fixture
开发语言·python·pytest
Mr_Xuhhh9 天前
pytest -- 指定⽤例执⾏顺序
开发语言·python·pytest
Mr_Xuhhh9 天前
pytest -- ⽇志与测试报告
pytest
西游音月11 天前
(5)pytest+Selenium自动化测试-元素定位之XPath定位
selenium·测试工具·pytest