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

相关推荐
cendy-LL6 小时前
自动化测试之Pytest框架
pytest
我的xiaodoujiao12 小时前
API 接口自动化测试详细图文教程学习系列7--相关Python基础知识6
python·学习·测试工具·pytest
忘忧记13 小时前
pytest + YAML + requests`简单实例化
网络·pytest
我的xiaodoujiao18 小时前
API 接口自动化测试详细图文教程学习系列8--测试接口
python·学习·测试工具·pytest
鹿鸣悠悠3 天前
pytest + requests + allure 接口自动化测试框架指南
pytest
忘忧记3 天前
pytest进阶参数化用法
前端·python·pytest
bug_rabbit3 天前
pytest-html 中文乱码问题终极解决方案(Windows版)
windows·html·pytest
庄小法3 天前
pytest
开发语言·python·pytest
工具人55554 天前
pytest练习
pytest
好家伙VCC4 天前
# Pytest发散创新:从基础测试到智能断言的实战进阶指南在现代软
java·python·pytest