pytest之测试用例参数化时用例名称有中文,输出到控制台显示成uincode编码的问题
一、在测试用例所在的目录下的conftest.py文件中添加钩子函数pytest_collection_modifyitems(items)即可
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")
二、输出结果,可以看到已经显示的是中文
E:\PycharmProjects\PythonVirtualenv\envWeatherWSWeb\Scripts\python.exe E:/PycharmProjects/apiWeatherWSWeb/runtest.py E:\PycharmProjects\apiWeatherWSWeb\testcase\test_getSupportCityDataset\test_GetSupportCityDataset.py::test_paramOfDataRightrequest ============================= test session starts ============================= platform win32 -- Python 3.6.0, pytest-5.3.5, py-1.8.1, pluggy-0.13.1 -- E:\PycharmProjects\PythonVirtualenv\envWeatherWSWeb\Scripts\python.exe cachedir: .pytest_cache rootdir: E:\PycharmProjects\apiWeatherWSWeb plugins: allure-pytest-2.8.11 collecting ... collected 228 items testcase/test_getSupportCityDataset/test_GetSupportCityDataset.py::test_paramOfDataRightrequest[验证theRegionCode字段为342时,响应结果是否正确] PASSED