美文网首页
pytest运行用例时,用例名中文显示为unicode编码问题解

pytest运行用例时,用例名中文显示为unicode编码问题解

作者: DayBreakL | 来源:发表于2020-06-11 09:52 被阅读0次

python3使用pytest写测试用例,中文显示为unicode编码“\u767b\u5f55\u6210\u529f”

解决:
在最高级别的conftest.py添加如下代码即可。

def pytest_collection_modifyitems(items):
    """
    测试用例收集完成时,将收集到的item的name和nodeid的中文显示在控制台上
    :return:
    """
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")

效果:


相关文章

网友评论

      本文标题:pytest运行用例时,用例名中文显示为unicode编码问题解

      本文链接:https://www.haomeiwen.com/subject/juvvtktx.html