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

相关推荐
丿罗小黑4 小时前
Pytest项目_day01(HTTP接口)
网络协议·http·pytest
活跃家族6 小时前
Python的Pytest(2)
开发语言·python·pytest
开源优测2 天前
深度剖析:Pytest Fixtures如何重塑自动化测试的可读性与高效性
pytest
南部余额2 天前
使用python反射,实现pytest读取yaml并发送请求
python·pytest
程序员念姐3 天前
Selenium+Pytest自动化测试框架实战
selenium·测试工具·pytest
Test.X4 天前
学习15天:pytest
学习·pytest
one day3214 天前
pytest 框架学习总结
学习·pytest
天才测试猿4 天前
Pytest自动化测试框架pytest-xdist分布式测试插件
自动化测试·软件测试·分布式·python·测试工具·测试用例·pytest
qq_433716955 天前
压力测试Monkey命令参数和报告分析!
自动化测试·selenium·测试工具·单元测试·pytest·接口测试·压力测试
测试渣5 天前
API自动化测试实战:Postman + Newman/Pytest的深度解析
pytest·postman