一、在測試用例所在的目錄下的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