Suppress pytest warnings for other peoples code only

﹥>﹥吖頭↗ 提交于 2021-02-07 14:21:24

问题


I'm trying out pytest for the first time. How do I suppress warnings issued about other peoples code that my code depends on without suppressing warnings about my own code?

Right now I have this in my pytest.ini so I don't have to see pytest warn me about some deprecation on the jsonschema package that I'm using.

[pytest]
filterwarnings =
    ignore::DeprecationWarning

But now if I write anything in my own code that should fire of a deprecation warning I'll miss it.


回答1:


The syntax for pytest-warning is action:message:category:module:lineno. You can use this config for ignoring only jsonschema:

[pytest]
filterwarnings =
    ignore::DeprecationWarning:jsonschema

You can also use regex in those fields. If you want to exclude all warnings except yours:

[pytest]
filterwarnings =
    ignore::DeprecationWarning:!yourtestmodule

Pytest uses the same filterwarning as python. You can learn more about python warnings here: https://docs.python.org/3/library/warnings.html#warning-filter

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



来源:https://stackoverflow.com/questions/54722420/suppress-pytest-warnings-for-other-peoples-code-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!