前言
使用 pytest.mark.parametrize 参数化的时候,加 ids 参数用例描述有中文时,在控制台输出会显示unicode编码,中文不能正常显示。
使用 pytest_collection_modifyitems 钩子函数,对输出的 item.name 和 item.nodeid 重新编码。
问题描述
参数化 ids 用例描述有中文
import pytest
# test_ids.py
import pytest
# 作者:上海-悠悠
def login(username, password):
'''登录'''
# 返回
return {"code": 0, "msg": "success!"}
# 测试数据
test_datas = [
({"username": "yoyo1", "password": "123456"}, "success!"),
({"username": "yoyo2", "password": "123456"}, "success!"),
({"username": "yoyo3", "password": "123