使用pytest实现参数化后,控制台输出的日志是乱码

测试用例id显示的是乱码

问题

testcases/test_测试用例.py::TestPro::test_测试用例_用例1**\\u5fc3\\u453g2** PASSED 33%

要让 pytest 在参数化测试中正确显示中文用例名称而非 Unicode 转义字符,可以通过以下两种方法

解决:

全局禁用测试 ID 转义

在项目根目录创建 pytest.ini 文件,并添加以下配置:

ini 复制代码
[pytest]
disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True

注意 :此选项会禁用所有测试 ID 的转义,确保用例名称不含特殊字符(如 /、: 等),否则可能引发路径问题。

补充说明

  • 编码一致性 :确保测试文件保存为 UTF-8 格式。
  • 终端/IDE 支持:确认运行环境(如终端或 IDE)支持 UTF-8 编码,避免乱码。

选择任一方法即可解决 Unicode 转义问题。推荐优先使用 ids 参数,以保持作用域局部性。

相关推荐
把头塞进显示器3 天前
电商平台-测试报告
python·selenium·pytest
昔我往昔8 天前
pytest日志问题排查记录
python·pytest
黄昏恋慕黎明11 天前
博客论坛技术迭代
python·pytest
2601_9620782311 天前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ11 天前
python+pytest+01
python·pytest
2601_9620782312 天前
Python接口自动化框架:pytest
python·pytest·接口自动化·测试框架·restfulapi
2601_9620781912 天前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
2601_9622845014 天前
安卓APP UI自动化测试:Python + UiAutomator2 + pytest + pytest-html
python·pytest·uiautomator2·ui自动化测试·安卓app
2601_9623008114 天前
基于pytest的接口自动化测试:使用requests模块的实战项目与接口关联方法详解
接口自动化测试·测试用例·pytest·接口关联·requests模块
2601_9623008114 天前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests