zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    Selenium系列(十五)
    Selenium系列(十四)
    Selenium系列(十三)
    Selenium系列(十二)
    Linux常用命令
    Linux
    Linux常用命令
    Linux常用命令
    Mysql常用sql语句(2)- 操作数据表
    Linux常用命令
  • 原文地址:https://www.cnblogs.com/Zhan-W/p/13037527.html
Copyright © 2011-2022 走看看