You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow up to #9386, starting this thread to discuss how to support the use case of "inside the given with block, no warning should be generated".
Seems most users assumed this idiom:
withpytest.warns(None):
...
Would ensure that the code inside the with block would not issue any warning, raising an error if it did.
However that was never the case, and pytest.warns(None) would do nothing (warning or no warning generated). To warn users about this common mistake, we added a deprecation warning when None was passed to pytest.warns (#8677).
When 7.0.0rc1 was released, some issues were reported about this: #9402, #9386.
Users would like a way to ensure a block of code does not raise any warning, something which we never really supported.
Our current suggestion is to use warnings.catch_warnings(), followed by simplefilter("error"):
Follow up to #9386, starting this thread to discuss how to support the use case of "inside the given with block, no warning should be generated".
Seems most users assumed this idiom:
Would ensure that the code inside the
withblock would not issue any warning, raising an error if it did.However that was never the case, and
pytest.warns(None)would do nothing (warning or no warning generated). To warn users about this common mistake, we added a deprecation warning whenNonewas passed topytest.warns(#8677).When
7.0.0rc1was released, some issues were reported about this: #9402, #9386.Users would like a way to ensure a block of code does not raise any warning, something which we never really supported.
Our current suggestion is to use
warnings.catch_warnings(), followed bysimplefilter("error"):However as mentioned in #9402, this does not apply directly if you have a dynamic check:
So far we have the following proposals:
catch_warnings(Improve pytest.warns() docs to clarify difference with catch_warnings() #9002).pytest.does_not_warn()([prerelease] pytest.warns() doesn't seem to work properly for coverage.py #9386 (comment)).pytest.warns(None)to mean that no warning should be raised (FR: Revert pytest.warns(None) changes #9402 (comment)).I think this is worth reaching a consensus before the
7.0.0release is out.