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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM