pytest报错警告处理一:DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

在学习pytest时执行用例遇到一个警告,内容如下:

DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

大致意思是:弃用警告:从collections中导入ABCs已被弃用,并在python3.8中将停止工作,可使用collections.abc代替它进行使用

然后就各种百度了解,主要看到两种解决办法,做一下简单汇总:

第一种: 在代码文件中用到了 collections 这个模块的报错;

第二种:在代码文件中没有用到  collections 这个模块的报错;

对应的解决办法:

第一种情况的解决办法:

# from collections import Iterable   ---这是会报警告的用法
from collections.abc import Iterable ---这是不会报警告的用法
print(isinstance('abc', Iterable))

第二种情况的解决办法:

这种比较坑,因为确实没有用到,所有就没办法修改导入内容来干掉警告,我就是这种情况。。

但是万能的人啊!有了解决办法

1、新建一个文件: pytest.ini

2、文件中写入:

[pytest]
addopts = -p no:warnings

然后再去玩一下警告就没有了!!!!

posted @ 2020-06-03 14:52  漂泊的小虎  阅读(4294)  评论(0编辑  收藏  举报