【问题标题】:How to disable PytestDeprecationWarning: direct construction of Flake8Item has been deprecated, please use Flake8Item.from_parent如何禁用 PytestDeprecationWarning:直接构建 Flake8Item 已被弃用,请使用 Flake8Item.from_parent
【发布时间】:2020-04-04 15:14:34
【问题描述】:
  • ????当我在项目文件夹中运行 python setup.py test 命令以使用 setup.cfg 配置测试我的包时,我收到了此警告消息。
  • ????如何禁用它?

??????‍???? python setup.py test 的作用类似于 pytest --flake8 命令。

============================================================================================== warnings summary =============================================================================================== 
c:\users\yedhrab\appdata\local\programs\python\python38\lib\site-packages\pytest_flake8.py:65
  c:\users\yedhrab\appdata\local\programs\python\python38\lib\site-packages\pytest_flake8.py:65: PytestDeprecationWarning: direct construction of Flake8Item has been deprecated, please use Flake8Item.from_parent
    return Flake8Item(

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================================================================================== short test summary info =========================================================================================== 
SKIPPED [1] c:\users\***\appdata\local\programs\python\python38\lib\site-packages\pytest_flake8.py:106: file(s) previously passed FLAKE8 checks
=================================================================================== 9 passed, 1 skipped, 1 warning in 0.33s =================================================================================== 

【问题讨论】:

  • 请不要“标记”您的标题。这就是... 标签 的用途。 绝对请不要用表情符号污染它。 非常偶尔,明智地使用表情符号可能是可以接受的,具体取决于上下文。
  • 感谢您对标签的建议。对于 Emojis:Emojies 使上下文更易于理解,因为当您将图像与丑陋的线条文本进行比较时,我们的大脑更有效地理解图像。表情符号会影响情绪,如果您在学习某件事时没有感受到任何情绪,您可能会忘记它。
  • Here is a meta post 鼓励用户编辑过多的表情符号。没有明确的规则,但允许用户编辑彼此内容的系统是有原因的。

标签: python pytest flake8


【解决方案1】:

如果您不想禁用所有警告,而只想禁用特定的 pytest 警告,请使用 -W 参数:

pytest -W ignore::pytest.PytestDeprecationWarning

【讨论】:

    【解决方案2】:

    如果您确实需要,您应该使用 --disable-warnings 标志来消除特定测试的警告。

    pytest --disable-warnings
    

    运行pytest --help查看更多详情。

    【讨论】:

    • 我无法使用此选项抑制警告。 -W ignore::pytest.PytestDeprecationWarning 工作正常
    【解决方案3】:

    我通过将这些行添加到我的 setup.cfg 解决了这个问题

    [tool:pytest]
    # ...
    filterwarnings =
        ignore::DeprecationWarning
    

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 2021-05-20
      • 2020-05-30
      • 1970-01-01
      相关资源
      最近更新 更多