一、偶尔在编写接口自动化测试时,会出现一些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