一、偶爾在編寫接口自動化測試時,會出現一些warning警告信息,例如
============================== warnings summary =============================== utils\myenum.py:14 E:\PycharmProjects\apiWeatherWSWeb\utils\myenum.py:14: PytestCollectionWarning: cannot collect test class 'TestEnum' because it has a __new__ constructor (from: testcase/test_getWeather/test_GetWeather.py) class TestEnum(Enum): -- Docs: https://docs.pytest.org/en/latest/warnings.html ======================== 2 passed, 1 warning in 2.54s =========================
二、警告信息並不是用例執行失敗或跳過,不影響測試用例的執行結果。可以在pytest.ini文件中進行配置來消除警告信息
[pytest] filterwarnings = error ignore::UserWarning
注意:這將忽略所有的用戶警告信息。暫時收集到的用戶警告信息如:PytestCollectionWarning
三、再次運行測試用例,可以看到已經消除警告信息
============================== 2 passed in 2.74s ============================== Process finished with exit code 0
特別:更多關於pytest的警告信息的官網地址:https://docs.pytest.org/en/latest/warnings.html