gpt4 book ai didi

pytest - 仅抑制其他人代码的 pytest 警告

转载 作者:行者123 更新时间:2023-12-04 19:26:33 26 4
gpt4 key购买 nike

我正在试用 pytest首次。我如何抑制发出的关于我的代码所依赖的其他人的代码的警告而不抑制关于我自己的代码的警告?

现在我的 pytest.ini 中有这个所以我不必看到 pytest 警告我关于 jsonschema 的一些弃用我正在使用的包。

[pytest]
filterwarnings =
ignore::DeprecationWarning

但是现在,如果我在自己的代码中编写任何应该触发弃用警告的内容,我就会错过它。

最佳答案

pytest-warning 的语法是 action:message:category:module:lineno .您可以使用此配置仅忽略 jsonschema:

[pytest]
filterwarnings =
ignore::DeprecationWarning:jsonschema

您还可以在这些字段中使用正则表达式。如果您想排除除您之外的所有警告:
[pytest]
filterwarnings =
ignore::DeprecationWarning:!yourtestmodule

Pytest 使用与 python 相同的过滤器警告。您可以在此处了解有关 Python 警告的更多信息: https://docs.python.org/3/library/warnings.html#warning-filter

来源: https://github.com/fschulze/pytest-warnings/blob/master/pytest_warnings/init.py#L18

关于pytest - 仅抑制其他人代码的 pytest 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54722420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com