pytest -Werror
中止。
在我的情况下,警告是DeprecationWarning
,所以我无法通过例外类别禁用此警告,因为它太宽了,也影响了其他代码。
我如何压制第三方图书馆警告,以便pytest忽略它们? 我尝试过:
with warnings.catch_warnings():
call_third_party_code_with_warnings()
pytest
仍然将测试终止为
ERROR
,而忽略了warnings.catch_warnings
。
特别警告是 File "/Users/moo/Library/Caches/pypoetry/virtualenvs/trade-executor-8Oz1GdY1-py3.10/lib/python3.10/site-packages/jsonschema/validators.py", line 196, in __init_subclass__
warnings.warn(
DeprecationWarning: Subclassing validator classes is not intended to be part of their public API. A future version will make doing so an error, as the behavior of subclasses isn't guaranteed to stay the same between releases of jsonschema. Instead, prefer composition of validators, wrapping them in an object owned entirely by the downstream library.
pyproject.toml
flag异常。
-Werror
您可以在
filterwarnings = [
"ignore:::.*.jsonschema",
# DeprecationWarning: Subclassing validator classes is not intended to be part of their public API. A future version will make doing so an error, as the behavior of subclasses isn't guaranteed to stay the same between releases of jsonschema. Instead, prefer composition of validators, wrapping them in an object owned entirely by the downstream library.
"ignore:::.*.validators",
"ignore::DeprecationWarning:openapi_spec_validator.*:"
]
中添加filterwarnings
pytest.ini
或如果您喜欢的话,请忽略此库中的所有内容
[pytest]
filterwarnings = ignore::DeprecationWarning:THIRD_PARTY_NAME.*:
filterwarnings = ignore:::.*.THIRD_PARTY_NAME
标志,您可以使用
-Werror
pytest.ini
[pytest]
filterwarnings =
error
ignore::DeprecationWarning
.中提出的。
您可以尝试类似builtins.py
的事情,但我怀疑它会起作用。
看起来这不是在
ignore::jsonschema.validators.DeprecationWarning
中实现的。在Pytest Github repo上有一张售票。