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

相关推荐
摘星编程1 天前
AI 帮我写单测:pytest 覆盖率提升 40% 的协作日志
人工智能·pytest·测试驱动开发·代码覆盖率·ai协作开发
lucia_zl4 天前
pytest并发测试,资源问题导致用例失败解决办法
pytest
鱼鱼说测试4 天前
Selenium4+Pytest自动化测试框架实战
pytest
XYiFfang10 天前
【Pytest】解决Pytest中Teardown钩子的TypeError:实例方法与类方法的调用差异
python·pytest
Kingairy12 天前
Pytest 插件:pytest_runtest_protocol
python·pytest
AIZHINAN12 天前
Pytest 插件介绍和开发
测试工具·pytest·插件开发
灰阳阳14 天前
替身演员的艺术:pytest-mock 从入门到飙戏
自动化测试·python·pytest·unit testing·pytest-mock
年年测试18 天前
Playwright与PyTest结合指南
pytest
focksorCr18 天前
pytest 并发执行用例(基于受限的测试资源)
python·pytest