【问题标题】:DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0弃用警告:inspect.getargspec() 自 Python 3.0 起已弃用
【发布时间】:2020-05-21 20:33:46
【问题描述】:

我有使用python3.6 的项目,我使用pytest 进行测试。一切正常,但是当我运行 py.test 时突然收到此警告消息

===============警告总结===========

/usr/local/lib/python3.6/dist-packages/gevent/monkey.py:685
/usr/local/lib/python3.6/dist-packages/gevent/monkey.py:685: 弃用警告:inspect.getargspec() 自 Python 以来已弃用 3.0,使用inspect.signature() 或inspect.getfullargspec() patch_all_args = getargspec(patch_all)[0] # pylint:disable=deprecated-method

-- 文档:https://docs.pytest.org/en/latest/warnings.html

首先,我没有改变任何东西。其次,警告是针对monkey.py 中的python3.6

为什么我应该在我的项目中收到这个警告,我该如何解决这个问题?

【问题讨论】:

  • 它告诉您monkey.py 正在使用已弃用的方法。如果可能,您可以通过升级 gevent 来解决此问题,或者您可以更新您的 pytest 配置以忽略 DeprecationWarning

标签: python python-3.x pytest


【解决方案1】:

参考documents,我发现我有两种方法可以禁用此警告:

  1. 在命令行中将-p no:warnings 传递给py.test

    py.test -p no:warnings
    
  2. 通过修改pytest.ini,一劳永逸地禁用弃用警告:

    [pytest]
    
    filterwarnings =
        ignore:.*U.*mode is deprecated:DeprecationWarning
    

【讨论】:

  • 禁用警告通常是一个坏主意——警告是为了告诉你一些重要的事情(在这种情况下,你所依赖的某些代码将在未来的版本中停止工作)。消除警告的原因(在这种情况下,通过升级发出警告的依赖项)是非常可取的。
猜你喜欢
  • 2021-02-19
  • 1970-01-01
  • 2020-12-06
  • 2015-03-23
  • 2019-07-09
  • 1970-01-01
相关资源
最近更新 更多