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

相关推荐
奶茶精Gaaa4 天前
pytest
pytest
霍格沃兹测试开发学社测试人社区6 天前
软件测试学习笔记丨Pytest 学习指南
软件测试·笔记·测试开发·学习·pytest
神即道 道法自然 如来7 天前
测试面试题:pytest断言时,数据是符点类型,如何断言?
pytest
high_tea8 天前
pytest - 多线程提速
python·pytest
傻啦嘿哟9 天前
自动化测试框架集成:将Selenium集成到pytest与unittest中
selenium·测试工具·pytest
一名在八月份找工作的测试员10 天前
自动化学习1:pytest自动化框架的基本用法:注意事项/断言assert/测试结果分析
学习·自动化·pytest
什么时候才能变强11 天前
Pytest-如何将allure报告发布至公司内网
linux·服务器·pytest
一名在八月份找工作的测试员11 天前
自动化学习2:pytest的高级用法(mark标记/fixture/hook)
学习·自动化·pytest
测试199812 天前
Python+requests+pytest+allure自动化测试框架
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest