【发布时间】:2018-01-22 03:10:03
【问题描述】:
我想确保在一个断言中根本没有警告。
在pytest documentation about warnings 中找不到任何明确的答案。
我试过这个,我想None 可能意味着“什么都没有”:
def test_AttrStr_parse_warnings():
"""Check _AttrStr.parse() raises proper warnings in proper cases."""
with pytest.warns(None):
_AttrStr('').parse()
但这个断言也总是正确的,例如,测试不会失败,即使实际引发了警告:
def test_AttrStr_parse_warnings():
"""Check _AttrStr.parse() raises proper warnings in proper cases."""
with pytest.warns(None):
_AttrStr('').parse()
warnings.warn('any message')
【问题讨论】:
标签: python python-3.x unit-testing warnings pytest